spring - beans.factory.BeanCreationException: Error creating bean with name 'dao': Injection of persistence dependencies failed -
i trying run project, these following exceptions:
exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'dao': injection of persistence dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [applicationcontext.xml]: invocation of init method failed; nested exception javax.persistence.persistenceexception: [persistenceunit: my_p_u] unable build entitymanagerfactory @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:342) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1106) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:585) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:913) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:464) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:93) @ test.test.main(test.java:9) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [applicationcontext.xml]: invocation of init method failed; nested exception javax.persistence.persistenceexception: [persistenceunit: my_p_u] unable build entitymanagerfactory @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1455) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.finddefaultentitymanagerfactory(persistenceannotationbeanpostprocessor.java:530) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.findentitymanagerfactory(persistenceannotationbeanpostprocessor.java:496) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.resolveentitymanager(persistenceannotationbeanpostprocessor.java:657) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.getresourcetoinject(persistenceannotationbeanpostprocessor.java:630) @ org.springframework.beans.factory.annotation.injectionmetadata$injectedelement.inject(injectionmetadata.java:150) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:339) ... 13 more caused by: javax.persistence.persistenceexception: [persistenceunit: my_p_u] unable build entitymanagerfactory @ org.hibernate.ejb.ejb3configuration.buildentitymanagerfactory(ejb3configuration.java:911) @ org.hibernate.ejb.hibernatepersistence.createcontainerentitymanagerfactory(hibernatepersistence.java:74) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:268) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:310) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1514) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1452) ... 26 more caused by: org.hibernate.mappingexception: repeated column in mapping entity: org.gestion.infopanne.entities.simplemessage column: genre (should mapped insert="false" update="false") @ org.hibernate.mapping.persistentclass.checkcolumnduplication(persistentclass.java:675) @ org.hibernate.mapping.persistentclass.checkpropertycolumnduplication(persistentclass.java:697) @ org.hibernate.mapping.persistentclass.checkcolumnduplication(persistentclass.java:719) @ org.hibernate.mapping.persistentclass.validate(persistentclass.java:473) @ org.hibernate.mapping.singletablesubclass.validate(singletablesubclass.java:65) @ org.hibernate.cfg.configuration.validate(configuration.java:1332) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1835) @ org.hibernate.ejb.ejb3configuration.buildentitymanagerfactory(ejb3configuration.java:902) ... 31 more
by way, added these dependencies before starting project :
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${org.springframework-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>${org.springframework-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-tx</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-commons-annotations</artifactid> <version>3.2.0.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>3.6.0.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>4.1.0.final</version> </dependency> <dependency> <groupid>org.hibernate.javax.persistence</groupid> <artifactid>hibernate-jpa-2.0-api</artifactid> <version>1.0.0.final</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.6</version> </dependency>
and finally, applicationcontext.xml looks this:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <bean id="dao" class="org.gestion.infopanne.dao.fonctionsdaoimplem"> </bean> <bean id="metier" class="org.gestion.infopanne.metier.fonctionsmetierimplem"> <property name="dao" ref="dao"></property> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver"> </property> <property name="url" value="jdbc:mysql://localhost:3306/panne"> </property> <property name="username" value="root"></property> <property name="password" value=""></property> </bean> <bean id="persistenceunitmanager" class="org.springframework.orm.jpa.persistenceunit.defaultpersistenceunitmana ger"> <property name="persistencexmllocations"> <list> <value>classpath*:meta-inf/persistence.xml</value> </list> </property> <property name="defaultdatasource" ref="datasource"></property> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="persistenceunitmanager" ref="persistenceunitmanager"> </property> <property name="persistenceunitname" value="my_p_u"></property> </bean> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory"> </property> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <context:annotation-config></context:annotation-config>
package org.gestion.infopanne.entities; import java.util.date; import javax.persistence.discriminatorvalue; import javax.persistence.entity; @entity @discriminatorvalue("simple") public class simplemessage extends message{ public simplemessage() { super(); } public simplemessage(string materiel, string description,string genre, string date) { super(materiel, description, genre, date); } }
message class:
package org.gestion.infopanne.entities; import java.io.serializable; import java.util.date; import javax.persistence.discriminatorcolumn; import javax.persistence.discriminatortype; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.inheritance; import javax.persistence.inheritancetype; import javax.persistence.joincolumn; import javax.persistence.manytoone; @entity @inheritance(strategy=inheritancetype.single_table) @discriminatorcolumn(name="genre",discriminatortype=discriminatortype.string) public class message implements serializable { @id @generatedvalue(strategy=generationtype.identity) private int idm; private string materiel; private string description; private string genre; private string date; @manytoone @joincolumn(name="idm") private utilisateur user; public message() { super(); // todo auto-generated constructor stub } public message(string materiel, string description,string genre, string date) { super(); this.materiel = materiel; this.description = description; this.genre = genre; this.date = date; } public int getid() { return idm; } public void setid(int id) { this.idm = id; } public string getmateriel() { return materiel; } public void setmateriel(string materiel) { this.materiel = materiel; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getgenre() { return genre; } public void setgenre(string genre) { this.genre = genre; } public string getdate() { return date; } public void setdate(string date) { this.date = date; } public utilisateur getuser() { return user; } public void setuser(utilisateur user) { this.user = user; } }
according 2 links:
http://www.springbyexample.org/examples/jpa-joined-inheritance-jpa-entity-config.html
https://en.wikibooks.org/wiki/java_persistence/inheritance
i think have remove line message class:
private string genre;
and getter , setter methods, because defined column discriminationcolumn annotation:
@discriminatorcolumn(name="genre",discriminatortype=discriminatortype.string)
Comments
Post a Comment