[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-3398) _BackRef issue in Parent Child relation while inserting both records in one table (Recursive Relation)

Gail Badner (JIRA) noreply at atlassian.com
Sun Aug 17 21:26:38 EDT 2008


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gail Badner resolved HHH-3398.
------------------------------

      Assignee: Gail Badner
    Resolution: Rejected

Please use the user forum to ask for help.

> _BackRef issue in Parent Child relation while inserting both records in one table (Recursive Relation) 
> -------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3398
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3398
>             Project: Hibernate3
>          Issue Type: Bug
>         Environment: Hibernate 3.0
> MS SQL Server
>            Reporter: Vivek Sharma
>            Assignee: Gail Badner
>
> Hi, I am new to hibernate and seems to be stuck in resolving this _backref issue. I have come across many parent child relation issues in forum but nowhere , I was able to find the scenerio where parent and child records are being inserted in the same table. That, is self refering table.
> First, I can not attach my test case as, I am working for a Investment Banking solution and sending of code is prohibited. So, I will try to put the identical scenerio here...
> I have a Leg which can have numerous Legs inside it. Thats, is Leg -> Leg -> Leg
> Now my class Leg.java is defined as below:
> public class Leg implements Serializable
> {
>   protected long id;
>   protected Leg parentLeg;
>   protected Set<Leg> legs;
>   protected String name;
> <!--- further getter and setter for the same is defined -->
> }
> My hbm looks like this:
> <class name="Leg" table="tblLeg">
> 		<id name="idLeg">
> 			<generator class="native" />
> 		</id>
>                                          <!-- Mapping Set<leg> attribute of the parent entity Leg -->
> 		<set name="legs" cascade="all" lazy="false" fetch="join"
> 			inverse="true">
> 			<key column="idParentLeg" />
> 			<one-to-many class="Leg" />
> 		</set>
> 		<many-to-one name="idParentLeg" class="Leg">
> 			<column name="idParentLeg" />
> 		</many-to-one>
>                                          <property name="name"/>
> </class>
> Now, i am inserting records inside the table using the following approach:
> Leg parentLeg = new Leg();
> parentLeg.setName("Parent Leg");
> parentLeg.setParentLeg(null);
> Leg childLeg = new Leg();
> childLeg.setName("Child Leg");
> childLeg.setParentLeg(parentLeg); // i am setting back referencing here
> childLeg.setLegs(null); // child has no child elements
> Set setLeg = new HashSet();
> setLeg.add(childLeg);
> parentLeg.setLegs(setLeg); // adding child elements to parent leg
> // this is how I am saving it in my test case:
> return (Long) getHibernateTemplate().save(entity);
> But when i do this, the parent leg is inserted successfully and after it throws the following stack trace:
> com.rbs.tradeservice.services.exception.ServiceException: com.rbs.tradeservice.services.exception.ServiceException: org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: com.rbs.tradeservice.jaxb.Leg._legsBackref; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.rbs.tradeservice.jaxb.Leg._legsBackref
> 	at com.rbs.tradeservice.util.LoggingAroundAdvice.invoke(LoggingAroundAdvice.java:83)
> 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:143)
> 	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:619)
> 	at com.rbs.tradeservice.services.tradeservice.impl.TradeDomainModelServiceImpl$$EnhancerByCGLIB$$cc0b0bf6.saveTradeDetails(<generated>)
> 	at com.rbs.tradeservice.services.tradeservice.impl.TradeDomainModelServiceImplTest.testSave(TradeDomainModelServiceImplTest.java:65)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Any help would be really appreciated... Someone suggested me to upgrade it to highre version to resolve this issue...

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list