• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error creating bean

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am doing a webapp with hibernate + spring + spring security + jsf.
when i try to execute my webapp, i got this error :
----------------------------------------------------------------------------------
SEVERE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactsDao' defined in ServletContext resource [/WEB-INF/ApplicationContext-Dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/ApplicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.oxia.formation.Contrats.client references an unknown entity: java.lang.String
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/ApplicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.oxia.formation.Contrats.client references an unknown entity: java.lang.String
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 28 more
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.oxia.formation.Contrats.client references an unknown entity: java.lang.String
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:499)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 38 more

nov. 24, 2012 6:18:41 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
nov. 24, 2012 6:18:41 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Erreur de démarrage du contexte [/GestionContrat] suite aux erreurs précédentes
nov. 24, 2012 6:18:41 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
nov. 24, 2012 6:18:41 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/GestionContrat] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
nov. 24, 2012 6:18:41 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/GestionContrat] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
nov. 24, 2012 6:18:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8880"]
nov. 24, 2012 6:18:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8889"]
nov. 24, 2012 6:18:41 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11632 ms
------------------------------------------------------------------------------------------------
ApplicationContext-Dao.xml file
-----------------------------------------------------------------------------------------------
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!--Transaction management -->
<bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"
/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<!-- other methods use the default transaction settings (see
below) -->
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!--
Ensure that the above transactional advice runs for any execution of
an operation defined by the userManagementService interface
-->
<aop:config>
<aop:pointcut id="managementServiceOperation" expression="execution(* com.oxia.formation.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="managementServiceOperation" />
</aop:config>
</beans>
-----------------------------------------------------------------------------------------------------------------------
my bean ContratCtr.java
-----------------------------------------------------------------------------------------------------------------------
package com.oxia.formation.ctr;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.springframework.dao.DataIntegrityViolationException;
import com.oxia.formation.Contacts;
import com.oxia.formation.Contrats;
import com.oxia.formation.dao.ContactsDao;
import com.oxia.formation.dao.ContratsDao;
public class ContactCtr implements Serializable {
private static final long serialVersionUID = 1L;
private ContratsDao contratsDao;
private ContactsDao contactsDao;
private DataModel features;
private Contacts selectedContact = new Contacts();
private Contacts contact;
private List<Contacts> contacts;
private List<Contrats> listeContrats;
private boolean creation;
@PostConstruct
public void init() {
contacts = contactsDao.getContacts();
features = new ListDataModel(contacts);
}
public DataModel getFeatures() {
contacts = contactsDao.getContacts();
features = new ListDataModel(contacts);
return features;
}
public List<Contacts> getContacts() {
contacts = contactsDao.getContacts();
features = new ListDataModel(contacts);
return contacts;
}
public String editContact() {
setSelectedContact(contacts.get(features.getRowIndex()));
setCreation(false);
return "success";
}
public String create() {
selectedContact = new Contacts();
setCreation(true);
return "success";
}
public String saveContact() {
contact = new Contacts();
contact.setCin(selectedContact.getCin());
contact.setFirstName(selectedContact.getFirstName());
contact.setLastName(selectedContact.getLastName());
contact.setEmail(selectedContact.getEmail());
try {
contactsDao.create(selectedContact);
} catch (DataIntegrityViolationException e) {
FacesContext.getCurrentInstance().addMessage(
"Exist",
new FacesMessage("L'identifiant saisi existe déjà dans la base"));
return "echec";
}
return "success";
}
public String updateContact() {
setCreation(false);
contactsDao.update(selectedContact);
return "success";
}
public String deleteContact() {
setCreation(false);
contactsDao.delete(contacts.get(features.getRowIndex()));
return "success";
}
public String getContactById() {
setCreation(false);
setSelectedContact(contactsDao.findById(selectedContact.getCin()));
listeContrats = contratsDao.findContratsByContact(selectedContact.getCin());
return "success";
}
public ContactsDao getContactDao() {
return contactsDao;
}
public void setContactsDao(ContactsDao contactsDao) {
this.contactsDao = contactsDao;
}
public Contacts getSelectedContact() {
return selectedContact;
}
public void setSelectedContact(Contacts selectedContact) {
this.selectedContact = selectedContact;
}
public boolean isCreation() {
return creation;
}
public void setCreation(boolean creation) {
this.creation = creation;
}
public ContratsDao getContratsDao() {
return contratsDao;
}
public void setContratsDao(ContratsDao contratsDao) {
this.contratsDao = contratsDao;
}
public List<Contrats> getListeContrats() {
return listeContrats;
}
public void setListeContrats(List<Contrats> listeContrats) {
this.listeContrats = listeContrats;
}
}
---------------------------------------------------------------------------
the web.xml file:
--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>jsfexemple</display-name>
<!-- Faces Servlet -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ApplicationContext*.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value> /WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
-------------------------------------------------------------------------------------
thanks to solve my problem.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please please use CODE tags when posting config or code. No one can read what you posted. Or will take the time to try to read it. There is a Code button to add the tags whenever you post here.

"Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.oxia.formation.Contrats.client references an unknown entity: java.lang.String "

Here is your error. You have a mapping problem, but I cannot read your code to even look at it. But I am also going to move this to the ORM forum since it is a Hibernate error and not a Spring issue.

Mark
 
Tsague ezequiel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi mark,
thank for your response,
i have a database with two tables.
here is the generated code from hibernate tools of contrats.java and contacts.java:


and contacts.java:



my bean ContactCtr


file ApplicationContext-Dao.xml

and my web.xml file :

thank for your help.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for using CODE tags. But the last three are missing indentation. I don't think your real file doesn't have indentation in it. Try to repost those. Thanks

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As, in my first reply your problem is



that is incorrect. String type is not an Entity, That mapping is expecting the one side to be an Entity representing a row in a database table. You have an Element of basic type, not an Entity there. String is NOT an Entity and cannot be used as one, and only Entities can be used with @ManyToOne

What does your db table look like that is holding that data?

Mark
 
Tsague ezequiel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
many thanks mark,


that is incorrect. String type is not an Entity, That mapping is expecting the one side to be an Entity representing a row in a database table



it work now.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tsague ezequiel wrote:many thanks mark,


that is incorrect. String type is not an Entity, That mapping is expecting the one side to be an Entity representing a row in a database table



it work now.



Very cool.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic