Hibernate version:
2.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="State" table="states" lazy="true">
<id name="id" column="id" type="string" unsaved-value="null">
<generator class="native"/>
</id>
<property name="countryId">
<column name="country_id" not-null="true"/>
</property>
<property name="name">
<column name="name" not-null="true"/>
</property>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="User" table="sp">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="email">
<column name="email" not-null="true"/>
</property>
<many-to-one name="state"
class="State"
column="state_id"
not-null="false" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
SEVERE: Exception initializing proxy
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: , of class: State
at net.sf.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:24)
at net.sf.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1945)
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:53)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:164)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hi,
I have the above mapping for a user which has a country and a state. Now, not all users have states and therefore the many-to-one mapping (User-->State) might NOT contain a state. I keep getting the above exception for users without states. I have defined the not-null="false" in hope this will work but it has not.
Is there a better mapping?
|