Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one-to-one mapping

 
Alex Elba
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have table (A) which has composite key id and name and have other table(B) which has only key id

some records with A can have B and A id and B id are same.


<class
name="A"
table="A">

<composite-id>
<key-property
name="id"
column="ID" />
<key-property
name="name"
column="NAME" />
</composite-id>
...
<many-to-one
name="b"
class="B"
column="id"
>
...
</class>

<class
name="B"
table="B">
<id
name="id"
column="ID" />
...
</class>


When I trying to get b for objects which doesn't have it (b is null) I am getting following exception


org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [B#7581385]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at B$$EnhancerByCGLIB$$getSuppressAddress(<generated>)


I was thinking to change it to one-to-one but I have composite key on A and single key on B...

Any suggestions what I am doing wrong?


Thanks


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic