Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'default' found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.javapassion.examples.student.Main.main(Main.java:15)
Caused by: java.lang.IllegalArgumentException: No persistence unit with name 'default' found
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.obtainPersistenceUnitInfo(DefaultPersistenceUnitManager.java:685)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.obtainDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:673)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.determinePersistenceUnitInfo(LocalContainerEntityManagerFactoryBean.java:363)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:312)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
... 12 more
<?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:p = "http://www.springframework.org/schema/p"
xmlns:aop = "http://www.springframework.org/schema/aop"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:tx = "http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
"
>
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<!-- import the dataSource definition -->
<import resource = "applicationContext-dataSource.xml" />
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, Hibernate-related settings for the sessionFactory definition below) -->
<context:property-placeholder location = "classpath:jdbc.properties" />
<!-- JPA EntityManagerFactory -->
<bean
id = "entityManagerFactory"
class = "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property name = "dataSource" ref = "dataSource" />
<property name = "jpaVendorAdapter">
<!-- Use Hibernate as JPA engine -->
<bean
class = "org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database = "${jpa.database}"
/>
</property>
<property name = "jpaProperties">
<props>
<prop key = "hibernate.dialect">${hibernate.dialect}</prop>
<prop key = "hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key = "hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key = "hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key = "hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
</props>
</property>
<property name = "persistenceXmlLocation" value = "classpath:META-INF/persistence.xml" />
</bean>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean
id = "transactionManager"
class = "org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref = "entityManagerFactory"
/>
<!-- ========================= BUSINESS OBJECT DEFINITION ========================= -->
<!--
Scan the classpath for annotated components that will be auto-registered
as Spring beans.
By default, the Spring-provided @Component, @Repository,
@Service, and @Controller stereotypes will be detected.
-->
<context:component-scan base-package = "com.javapassion.examples.student.dao" />
<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @Resource.
-->
<context:annotation-config />
<!--
Instruct Spring to perform declarative transaction management automatically
on annotated classes.
-->
<tx:annotation-driven />
</beans>
<persistence
xmlns = "http://java.sun.com/xml/ns/persistence"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "
http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
"
version = "2.0"
>
<persistence-unit name = "student" />
<persistence-unit name = "teacher" />
</persistence>
What i'm missing? i check all the files and project properties and the error persist.
I posible to modify the example "database_jpa_hibernate_engine" better than the database_hibernate_annotation_HibernateTemplate ???
Thank's
Karl
Sang, i have problems to complete the homework. After doing the changes to the code and run the Main.java, STS show me the following error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'default' found
--
You received this message because you are subscribed to the Google Groups "JPassion.com: Spring Framework Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpassion_spri...@googlegroups.com.
Visit this group at http://groups.google.com/group/jpassion_spring.
For more options, visit https://groups.google.com/d/optout.
-- ------------------------------------------------------------------- Sang Shin, sangshi...@gmail.com Founder and Chief Instructor of JPassion.com (JavaPassion.com) http://www.linkedin.com/in/javapassion (Linkedin) http://twitter.com/javapassion (Tweeter) Life is worth living... with Passion! Practically Free 3 to 5 days Live, Hands-on, Online Codecamps on Java,Spring,Hadoop,HTML5,Ruby/Rails,Grails,JavaScript/jQuery,Android http://jpassion.com/codecamps ----------------------------------------------------------------------
Yes, the file is in the META-INF directory
--
You received this message because you are subscribed to the Google Groups "JPassion.com: Spring Framework Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpassion_spri...@googlegroups.com.
Visit this group at http://groups.google.com/group/jpassion_spring.
For more options, visit https://groups.google.com/d/optout.