IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Persistance des données Java Discussion :

Hibernate, spring et sqlite


Sujet :

Persistance des données Java

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2015
    Messages : 58
    Points : 39
    Points
    39
    Par défaut Hibernate, spring et sqlite
    Bonjour à tous
    J'ai un problème avec sqlite3,hibernate et spring.En fait, si je démarre le programme et que j'appelle la méthode createType() qui permet de créer un type et qu'après j'appelle la méthode getAllTypes() j'ai bel et bien les valeurs de l'objet que je viens de créer qui s'affichent dans le navigateur.Mais si je vérifie avec un "select * from type" dans ma table type pour voir si l'objet a été ajouté dans ma table, j'ai aucun enregistrement.En plus,dès que je redemarre le programme et que j'appelle la méthode getAllTypes() pour consulter les données de ma table j'ai plus rien qui s'affiche dans mon navigateur.Encore, pour chaque démarrage on dirait que l'ID est reinitialisé puisqu'il commence à 1(par exemple si après avoir demarré mon programme je tente d'insérer 2 objets avec la methode createType() j'ai : ID = 1 et ID = 2 qui s'affiche dans mon navigateur).Donc si mes données ne sont pas enregistrées dans ma table où sont-ils passées? J'ai fait 2 enrgistrements manuellement dans ma table et j'arrive pas aussi à récupérer ces 2 enregistrements avec la méthodes getAllTypes() qui est censé me renvoyer tous les enregistrements de ma table.Je me dit qu'il y a peut-être un problème de communication entre mon programme et ma base de données.Merci d'avance pour vos aides.

    Voilà comment j'appelle mes méthodes dans le navigateurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    http://localhost:8080/types/getAllTypes
    http://localhost:8080/types/insert
    application.yml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    spring: 
     profile:dev 
    jpa:
     hibernate:
      hbm2ddl.auto:update
     properties:
      hibernate:
       dialect:org.hibernate.dialect.SQLiteDialect
     datasource:
      url:jdbc:sqlite:C:\Users\user pc\Desktop\PDF\testrest.db
      username:user
      password:password
      driverClassName:org.sqlite.JDBC
    Mes dependences dans le pom.xml pour la configuration de sqlite,hibernate and spring :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
     <parent> 
          <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <type>pom</type>
       </parent>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>5.2.12.Final</version>
            </dependency>
     
            <dependency>
                <groupId>org.xerial</groupId>
                <artifactId>sqlite-jdbc</artifactId>
                <version>3.20.1</version>
            </dependency>
     
            <dependency>
              <groupId>com.zsoltfabok</groupId>
              <artifactId>sqlite-dialect</artifactId>
              <version>1.0</version>
            </dependency>
     
            <dependency>
              <groupId>com.h2database</groupId>
              <artifactId>h2</artifactId>
              <version>1.4.196</version>
            </dependency>
     
            <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-entitymanager</artifactId>
             <version>5.2.12.Final</version>
            </dependency>
     
            <dependency> 
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId> 
           </dependency>
     
          <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
     
          <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-collections4</artifactId>
             <version>4.0</version>
          </dependency>
     
          <dependency>
             <groupId>javax.xml.bind</groupId>
             <artifactId>jaxb-api</artifactId>
             <version>2.3.0</version>
          <dependency>
    Ma table type:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    CREATE TABLE IF NOT EXISTS type(
      idType integer NOT NULL PRIMARY KEY AUTOINCREMENT,
      description varchar(256) NOT NULL
    )
    Mon entity type:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
     
    @Entity
    @Table(name="typedifficulte")
    public class Type {
     
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long idType;
        private String description;
        public Type() {
     
        }
     
        public Type(String description) {
            this.description = description;
        }
     
        public String getDescription() {
            return description;
        }
        public void setDescription(String description) {
            this.description = description;
        }
     
        public long getIdType() {
            return idType;
        }
        public void setIdType(long idType) {
            this.idType = idType;
        }
    }
    Mon interface TypeService :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    public interface TypeService {
        Collection<Type>  getAllTypes();
        Type createType(Type type);
    }
    Mon TypeServiceImpl :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    import javax.annotation.Resource;
     
    import org.apache.commons.collections4.IteratorUtils;
    import org.springframework.stereotype.Service;
     
    @Service(value="typeService")
    public class TypeServiceImpl implements TypeService {
     
        @Resource
        private TypeRepository typeRepository;
     
        @Override
        public Collection<Type> getAllTypes() {
            return  IteratorUtils.toList(this.typeRepository.findAll().iterator());
        }
     
        @Override
        public Type createType(Type type) {
            return this.typeRepository.save(type);
        }
     
        public TypeRepository getTypeRepository() {
            return typeRepository;
        }
     
        public void setTypeRepository(TypeRepository typeRepository) {
            this.typeRepository = typeRepository;   
        }
    }
    Mon TypeRepository :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    public interface TypeRepository extends CrudRepository<Type,Long> {
        Type findByDescription(String description);
    }
    Mon controlleur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    @RestController
    @RequestMapping(value ="/types")
    public class TypeController {
     
        @Resource
        private TypeService typeService;
     
        @RequestMapping(value= "/getAllTypes", method = RequestMethod.GET)
        public Collection<Type> getAllTypes() {
            return this.typeService.findAll();
        }
     
        @RequestMapping(value = "/insert",method = RequestMethod.GET)
        public Type createType() {
            return this.typeService.createType(new Type("test"));
        }
    }
    Et enfin ma classe de démarrage :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    @Configuration
    @EnableAutoConfiguration
    @ComponentScan
    public class MainLauncher {
        public static void main(String[] args) {
            SpringApplication.run(MainLauncher.class, args);
        }
    }

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Pourrais-tu donner les logs de démarrage de ton application?

    Aussi, pourquoi cette dépendance à H2 dans ton pom.xml? Tu ne devrais pas en avoir besoin. Es-tu sûr que ton application.yml est pris en compte? J'ai l'impression que tu fais tourner ton spring boot sur un DB h2 en mémoire.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2015
    Messages : 58
    Points : 39
    Points
    39
    Par défaut
    Bonjour,

    Citation Envoyé par tchize_ Voir le message
    Es-tu sûr que ton application.yml est pris en compte?
    Effectivement, application.yml n'est pas pris en compte puisque je viens de supprimer tous le code qu'il y a dedans et malgré ça l'application fonctionne comme lorsqu'il y était. Voici le log de démarrage :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    :: Spring Boot ::        (v1.5.8.RELEASE)
     
    2017-11-25 08:18:07.245  INFO 5112 --- [           main] source.MainLauncher                      : Starting MainLauncher on user with PID 5112 (started by user pc in C:\Users\user pc\Desktop\PDF\exorest)
    2017-11-25 08:18:07.261  INFO 5112 --- [           main] source.MainLauncher                      : No active profile set, falling back to default profiles: default
    2017-11-25 08:18:07.537  INFO 5112 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@768fc0f2: startup date [Sat Nov 25 08:18:07 WAT 2017]; root of context hierarchy
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/user%20pc/Desktop/PDF/apache-maven-3.5.2/repository/org/springframework/spring-core/4.3.12.RELEASE/spring-core-4.3.12.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
    WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    2017-11-25 08:18:15.931  INFO 5112 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
    2017-11-25 08:18:15.988  INFO 5112 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2017-11-25 08:18:15.991  INFO 5112 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23
    2017-11-25 08:18:16.556  INFO 5112 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2017-11-25 08:18:16.557  INFO 5112 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 9052 ms
    2017-11-25 08:18:17.459  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
    2017-11-25 08:18:17.470  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
    2017-11-25 08:18:17.471  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
    2017-11-25 08:18:17.472  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
    2017-11-25 08:18:17.472  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
    2017-11-25 08:18:17.472  INFO 5112 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'corsFilter' to: [/*]
    2017-11-25 08:18:19.554  INFO 5112 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
    2017-11-25 08:18:19.630  INFO 5112 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    	name: default
    	...]
    2017-11-25 08:18:19.937  INFO 5112 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.12.Final}
    2017-11-25 08:18:19.940  INFO 5112 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    2017-11-25 08:18:20.075  INFO 5112 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    2017-11-25 08:18:20.120  INFO 5112 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.SQLiteDialect
    2017-11-25 08:18:20.519  INFO 5112 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
    2017-11-25 08:18:22.541  INFO 5112 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@39a8e2fa'
    2017-11-25 08:18:22.550  INFO 5112 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2017-11-25 08:18:24.934  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@768fc0f2: startup date [Sat Nov 25 08:18:07 WAT 2017]; root of context hierarchy
    2017-11-25 08:18:25.295  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/delete/{id}],methods=[DELETE]}" onto public void source.TypeController.deleteType(java.lang.Long)
    2017-11-25 08:18:25.300  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/getTypeByID/{id}],methods=[GET]}" onto public source.Type source.TypeController.getTypeById(java.lang.Long)
    2017-11-25 08:18:25.303  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/insert],methods=[POST]}" onto public source.Type source.TypeController.createType(source.Type)
    2017-11-25 08:18:25.304  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/getAllTypes],methods=[GET]}" onto public java.util.Collection<source.Type> source.TypeController.getAllTypes()
    2017-11-25 08:18:25.306  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/update/{id}],methods=[PUT]}" onto public source.Type source.TypeController.updateType(java.lang.Long,source.Type)
    2017-11-25 08:18:25.308  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/types/description/{description}],methods=[GET]}" onto public source.Type source.TypeController.getTypeByDescription(java.lang.String)
    2017-11-25 08:18:25.329  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
    2017-11-25 08:18:25.330  INFO 5112 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
    2017-11-25 08:18:25.494  INFO 5112 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2017-11-25 08:18:25.508  INFO 5112 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2017-11-25 08:18:25.749  INFO 5112 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2017-11-25 08:18:26.634  INFO 5112 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2017-11-25 08:18:26.911  INFO 5112 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
    2017-11-25 08:18:26.948  INFO 5112 --- [           main] source.MainLauncher                      : Started MainLauncher in 21.357 seconds (JVM running for 23.425)
    Citation Envoyé par tchize_ Voir le message
    Aussi, pourquoi cette dépendance à H2 dans ton pom.xml?
    En fait si je mets pas cette dépendance j'ai un problème de Dialect.Si cette dépendance n'est pas celle de sqlite pourrez-vous me dire celle à utiliser pour sqlite pour définir le Dialect ou une technique pour le faire?

    Voici le log si je tente de démarrer l'application sans cette dépendance :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    :: Spring Boot ::        (v1.5.8.RELEASE)
     
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/user%20pc/Desktop/PDF/apache-maven-3.5.2/repository/org/springframework/spring-core/4.3.12.RELEASE/spring-core-4.3.12.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
    WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    2017-11-25 08:11:36.412  INFO 3156 --- [           main] source.MainLauncher                      : Starting MainLauncher on user with PID 3156 (started by user pc in C:\Users\user pc\Desktop\PDF\exorest)
    2017-11-25 08:11:36.432  INFO 3156 --- [           main] source.MainLauncher                      : No active profile set, falling back to default profiles: default
    2017-11-25 08:11:36.685  INFO 3156 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@119cbf96: startup date [Sat Nov 25 08:11:36 WAT 2017]; root of context hierarchy
    2017-11-25 08:11:45.133  INFO 3156 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
    2017-11-25 08:11:45.181  INFO 3156 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2017-11-25 08:11:45.184  INFO 3156 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23
    2017-11-25 08:11:46.199  INFO 3156 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2017-11-25 08:11:46.199  INFO 3156 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 9527 ms
    2017-11-25 08:11:46.727  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
    2017-11-25 08:11:46.738  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
    2017-11-25 08:11:46.739  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
    2017-11-25 08:11:46.739  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
    2017-11-25 08:11:46.740  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
    2017-11-25 08:11:46.740  INFO 3156 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'corsFilter' to: [/*]
    2017-11-25 08:11:46.907  WARN 3156 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    2017-11-25 08:11:46.913  INFO 3156 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2017-11-25 08:11:46.998  INFO 3156 --- [           main] utoConfigurationReportLoggingInitializer : 
     
    Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
    2017-11-25 08:11:47.016 ERROR 3156 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
     
    ***************************
    APPLICATION FAILED TO START
    ***************************
     
    Description:
     
    Cannot determine embedded database driver class for database type NONE
     
    Action:
     
    If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    Merci d'avance!!!

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par Ja Rasta Voir le message
    Bonjour,



    Effectivement, application.yml n'est pas pris en compte*
    Ben voilà où est ton problème

    Citation Envoyé par Ja Rasta Voir le message
    En fait si je mets pas cette dépendance j'ai un problème de Dialect.
    Non ton message d'erreur ne mentionne nulle part d'histoire de dialet. Il dit juste que t'as pas défini un DB à utiliser, donc il est passé sur le modèle bae de données embarqué, mais n'a pas trouvé de driver correspondant. Tout ça c'est la conséquence de ton application.yml pas pris en compte.

    Alors je ne suis pas un grand utilisateur de yml, mais il me semble au vu de la doc que

    pour configurer la datasource, les clés sont
    spring.datasource.url, spring.datasource.username, spring.datasource.password et spring.datasource.driver-class-name
    pour configurer jpa, les clés sont
    spring.jpa.hibernate.ddl-auto et spring.jpa.properties.*

    Ce qui devrais amener plutot à la structure yml suivante:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    spring: 
     profile:dev 
     jpa:
      hibernate:
       hbm2ddl.auto:update
      properties:
       hibernate:
        dialect:org.hibernate.dialect.SQLiteDialect
     datasource:
      url:jdbc:sqlite:C:\Users\user pc\Desktop\PDF\testrest.db
      username:user
      password:password
      driverClassName:org.sqlite.JDBC

    enfin ton application.yml doit se situer dans src/main/resources

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2015
    Messages : 58
    Points : 39
    Points
    39
    Par défaut
    Bonjour tchize_,

    Ton status d'Expert éminent sénior n'est vraiment pas pour rien et je profite de cette occasion pour te dire que ça fait longtemps que j'ai remarqué qu'à chaque fois que tu interviens dans une discussion, elle finit par avoir une solution tant que le demandeur fournit un peu d'effort.C'est vraiment important de savoir ce que l'on fait!!!
    Pour ce qui est de mon problème, j'ai remplacé application.yml par application.properties dans lequel j'ai mis les propriétés de configuration de la base de données et d'hibernate. Par ailleurs,je précise qu'il est nécessaire de configurer la stratégie de nommage d'Hibernate que j'ai laissé par défaut dans mon cas soit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
    Pouvez-vous peut-être m'expliquer le mécanisme qui a permis que ma méthode d'insertion(createType()) a fonctionné avec la dependence de H2 dans mon pom.xml vu que je n'ai pas de base de données H2 installée sur mon ordi?

    Merci beaucoup!!!

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    H2 est une base de donnée purement java. Tout comme SQLite, intégrer la librairie suffit à créer / interagir avec la base. En plus H2 est capable de faire des bases de données temporaires purement en mémoire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [hibernate][spring] première application
    Par iftolotfi dans le forum Hibernate
    Réponses: 2
    Dernier message: 01/06/2006, 07h03
  2. Réponses: 10
    Dernier message: 31/05/2006, 16h15
  3. [Hibernate - Spring] Spring => Version 2 d'Hibernate?
    Par cicolas dans le forum Hibernate
    Réponses: 2
    Dernier message: 30/05/2006, 16h22
  4. [hibernate][spring]requete select from where IN
    Par whilecoyote dans le forum Hibernate
    Réponses: 1
    Dernier message: 07/04/2006, 09h06
  5. [Hibernate][Spring] Session Hibernate initialisée
    Par mauvais_karma dans le forum Hibernate
    Réponses: 12
    Dernier message: 08/08/2005, 13h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo