-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: null id in entry (don't flush the Session after an ...)
PostPosted: Thu May 20, 2004 10:42 am 
Newbie

Joined: Tue Sep 16, 2003 4:59 am
Posts: 10
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show java code

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.