java - NullPointerException org.hibernate.cfg.OneToOneSecondPass.doSecondPass -
i using hibernate 3.0
i have following tables , corresponding entries,
table a: integer aid; integer bid; table b: integer bid; @entity @table(name="a") public class { @id @generatedvalue(strategy=generationtype.auto) @column(name="aid") integer aid; @onetoone(targetentity=b.class) @joincolumn(name="bid", referencedcolumnname="bid") b b; } @entity @table(name="b") public class b { @id @generatedvalue(strategy=generationtype.auto) @column(name="bid") integer bid; @onetoone(targetentity=a.class, mappedby="b") @joincolumn(referencedcolumnname="bid") a; }
when try run spring application above configuration, following error,
caused by: java.lang.nullpointerexception @ org.hibernate.cfg.onetoonesecondpass.dosecondpass(onetoonesecondpass.java:135) @ org.hibernate.cfg.configuration.secondpasscompile(configuration.java:1163) @ org.hibernate.cfg.annotationconfiguration.secondpasscompile(annotationconfiguration.java:316) @ org.hibernate.cfg.configuration.buildmappings(configuration.java:1148) @ org.springframework.orm.hibernate3.localsessionfactorybean.buildsessionfactory(localsessionfactorybean.java:720) @ org.springframework.orm.hibernate3.abstractsessionfactorybean.afterpropertiesset(abstractsessionfactorybean.java:188) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1545) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1483)
i need reference of in b, though b not having reference a.
the exception getting beacuse trying define mapping on both sides. if want reference of in b, should do
@entity @table(name="a") public class { @id @generatedvalue(strategy=generationtype.auto) @column(name="aid") integer aid; @onetoone(targetentity=b.class) b b; } @entity @table(name="b") public class b { @id @generatedvalue(strategy=generationtype.auto) @column(name="bid") integer bid; @onetoone(targetentity=a.class, mappedby="b") a; }
watch out bugs in older hibernate versions
Comments
Post a Comment