Hi,
Can someone help me with this concern ?
Many thx in advance
I'm using hibernate 2.1.2, mysql V3.X, jdk1.4.
I'm trying to insert two objects in the database
public class Site {
private Long id;
private String url;
private List news;
}
public class News {
private Long id;
private String author;
private String title;
private String description;
private String link;
private String pubDate;
private int hit;
}
Here is the mapping files
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="be.gfdi.portal.server.model.News"
dynamic-update="false"
dynamic-insert="false"
>
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="identity"/>
</id>
<property
name="author"
type="java.lang.String"
update="true"
insert="true"
column="author"
/>
<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="title"
/>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="description"
/>
<property
name="link"
type="java.lang.String"
update="true"
insert="true"
column="link"
/>
<property
name="pubDate"
type="java.lang.String"
update="true"
insert="true"
column="pubdate"
/>
<property
name="hit"
update="true"
insert="true"
column="hit"
/>
</class>
</hibernate-mapping>
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="be.gfdi.portal.server.model.Site"
dynamic-update="false"
dynamic-insert="false"
>
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="identity"/>
</id>
<property
name="url"
type="java.lang.String"
update="true"
insert="true"
column="url"
/>
<set name="news">
<key column="site_id"/>
<one-to-many class="be.gfdi.portal.server.model.News"/>
</set>
</class>
</hibernate-mapping>
Here is the stack trace I recieved when trying to insert a record
net.sf.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2605)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2429)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2422)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2224)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2203)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at be.gfdi.fwk.server.datastore.impl.hibernate.ThreadLocalSession.commit(ThreadLocalSession.java:77)
at be.gfdi.fwk.server.datastore.impl.hibernate.DSTxManagerImpl.commit(DSTxManagerImpl.java:38)
at be.gfdi.portal.server.dao.impl.TestSiteDAO.tearDown(TestSiteDAO.java:45)
at junit.framework.TestCase.runBare(TestCase.java:130)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:410)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:294)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:182)
|