-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with one-to-one mapping
PostPosted: Tue May 30, 2006 9:10 am 
Newbie

Joined: Tue May 30, 2006 8:25 am
Posts: 7
Hello...
i'm trying to use a simple one to one mapping but i had an exception when
i try to save a new instance of my object "Figlio", my settings are:

Hibernate version:
3.1.3

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping

>

<class
name="it.atscom.nes.model.Figlio"
table="FIGLIO"
>

<id
name="idFiglio"
column="ID_FIGLIO"
>

<!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
<generator class="foreign">

<!-- The generator-param tag is deprecated, use the @hibernate.generator and @hibernate.param tags instead -->
<param
name="property"
>
padre
</param>

</generator>

</id>

<one-to-one
name="padre"
constrained="true"
>

</one-to-one>

<property
name="descrizione1"
column="DES_FIGLIO_1"
length="50"
not-null="true"
>

</property>

<property
name="descrizione2"
column="DES_FIGLIO_2"
length="50"
not-null="true"
>

</property>

</class>

</hibernate-mapping>


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping

>

<class
name="it.atscom.nes.model.Padre"
table="PADRE"
>

<id
name="idPadre"
column="ID_PADRE"
type="java.lang.Long"
>

<!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
<generator class="native">

</generator>

</id>

<one-to-one
name="figlio"
>

</one-to-one>

<property
name="descrizione"
column="DES_PADRE"
length="50"
not-null="true"
>

</property>

</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Figlio figlio = new Figlio();
figlio.setDescrizione1("aaaa");
figlio.setDescrizione1("bbbb");

Padre padre = (Padre) dao.getObject(Padre.class, new Long(rb
.getString("padre.get.idPadre2")));

figlio.setPadre(padre);

dao.saveObject(figlio);

public class BaseDAOHibernate extends HibernateDaoSupport implements DAO {
protected final Log log = LogFactory.getLog(getClass());

/**
* @see it.atscom.nes.dao.DAO#saveObject(java.lang.Object)
*/
public void saveObject(Object o) {
getHibernateTemplate().saveOrUpdate(o);
}


Full stack trace of any exception that occurs:
[junit] Testcase: testInsertFiglioFromPadre(it.atscom.nes.dao.OneToOneDAOTest): Caused an ER
ROR
[junit] Unable to resolve property:
[junit] padre
[junit] ; nested exception is org.hibernate.HibernateException: Unable to resolve proper
ty:
[junit] padre
[junit]
[junit] org.springframework.orm.hibernate3.HibernateSystemException: Unable to resolve property:

[junit] padre
[junit] ; nested exception is org.hibernate.HibernateException: Unable to resolve proper
ty:
[junit] padre
[junit]
[junit] org.hibernate.HibernateException: Unable to resolve property:
[junit] padre
[junit]
[junit] at org.hibernate.tuple.EntityMetamodel.getPropertyIndex(EntityMetamodel.java:352)
[junit] at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplize
r.java:279)
[junit] at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractE
ntityPersister.java:3252)
[junit] at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:39)
[junit] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSav
eEventListener.java:91)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrReque
stedId(DefaultSaveOrUpdateEventListener.java:186)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(Defaul
tSaveOrUpdateEventListener.java:175)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(Defa
ultSaveOrUpdateEventListener.java:98)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSa
veOrUpdateEventListener.java:70)
[junit] at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
[junit] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
[junit] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:490)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTe
mplate.java:690)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.ja
va:365)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTempla
te.java:687)
[junit] at it.atscom.nes.dao.hibernate.BaseDAOHibernate.saveObject(BaseDAOHibernate.java:28)

[junit] at it.atscom.nes.dao.OneToOneDAOTest.testInsertFiglioFromPadre(OneToOneDAOTest.java:
66)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[junit] Test it.atscom.nes.dao.OneToOneDAOTest FAILED

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
[junit] ------------- Standard Output ---------------
[junit] Hibernate: select padre0_.ID_PADRE as ID1_88_1_, padre0_.DES_PADRE as DES2_88_1_, figlio
1_.ID_FIGLIO as ID1_89_0_, figlio1_.DES_FIGLIO_1 as DES2_89_0_, figlio1_.DES_FIGLIO_2 as DES3_89_0_
from PADRE padre0_ left outer join FIGLIO figlio1_ on padre0_.ID_PADRE=figlio1_.ID_FIGLIO where padr
e0_.ID_PADRE=?
[junit] ------------- ---------------- ---------------

Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 11:00 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
this belongs in the Hibernate users discussion, but the mapping appears correct...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.