-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with loading an row from database...
PostPosted: Sat Apr 09, 2005 4:42 pm 
Newbie

Joined: Sat Apr 09, 2005 4:05 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hello,
I'll be answering blows question with my comments.
Well I'm trying to create service of messages. I've two tables in database:
Subject and Message. Every Subject can contains many messages, but one messages belongs to only one subject, ufff...:)

Hibernate version: 2.0

Mapping documents:
Message.xml.hbm is:
<?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="barsze.msgservice.db.Message" table="message">

<id name="id" column="id_message" type="java.lang.Long" unsaved-value="null">
<generator class="increment" />
</id>

<property name="title" type="java.lang.String" not-null="true" />

<property name="date" type="java.sql.Timestamp" not-null="true" />

<property name="content" type="java.lang.String" not-null="true" />

<property name="author" type="java.lang.String" not-null="true" />

<many-to-one name="subject" column="id_subject"
class="barsze.msgservice.db.Subject" />

</class>
</hibernate-mapping>

and Subject.xml.hmb is:

<?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="barsze.msgservice.db.Subject" table="subject">

<id name="id" column="id_subject" type="java.lang.Long">
<generator class="increment" />
</id>

<property name="content" type="java.lang.String" not-null="true" />

<set name="messages" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column="id_subject" />
<one-to-many class="barsze.msgservice.db.Message" />
</set>

</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
I'm only using methods containing code like that:

HibernateTemplate template = getHibernateTemplate();
result = (Message) template.get( Message.class, id );

without opening session, beacuse i've read method's above are transactional (well, everything was working, till now);


Full stack trace of any exception that occurs:
No exceptions are thrown. There is assertion problem.

Name and version of the database you are using:
HSQLDB downloaded with hibernate.

The generated SQL (show_sql=true):
Till assertion error is occured the code is:
Hibernate: select subject0_.id_subject as id_subject0_, subject0_.content as content0_ from subject subject0_ where subject0_.id_subject=?
Hibernate: select messages0_.id_message as id_message__, messages0_.id_subject as id_subject__, messages0_.id_message as id_message0_, messages0_.title as title0_, messages0_.date as date0_, messages0_.content as content0_, messages0_.author as author0_, messages0_.id_subject as id_subject0_ from message messages0_ where messages0_.id_subject=?
Hibernate: select subject0_.id_subject as id_subject0_, subject0_.content as content0_ from subject subject0_ where subject0_.id_subject=?
Hibernate: select messages0_.id_message as id_message__, messages0_.id_subject as id_subject__, messages0_.id_message as id_message0_, messages0_.title as title0_, messages0_.date as date0_, messages0_.content as content0_, messages0_.author as author0_, messages0_.id_subject as id_subject0_ from message messages0_ where messages0_.id_subject=?
Hibernate: insert into message (title, date, content, author, id_subject, id_message) values (?, ?, ?, ?, ?, ?)
Hibernate: update subject set content=? where id_subject=?
Hibernate: update message set title=?, date=?, content=?, author=?, id_subject=? where id_message=?


Debug level Hibernate log excerpt:
I think it's default, i have changed anything in this case.

My problem is as follows:
I want to add a message to existing subject, so I coded:

Subject theSubject = subjectDao.selectById( subjectId );
theSubject.addMessage( addingMessage );

subjectDao.save( theSubject );

where addMessage method is:
...
Set messages;
...
public void addMessage( final Message message ) {
message.setSubject( this );

messages.add( message );
}

Now, I checked and THERE IS added message in database, but, when I try
to get subject (with added message) from database again, then there is no added message in set contained in Subject instance.
Hibernate seems not to load one row from database (lastrly added) but the row REALY is in database.

Thanks for help

Mike


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

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.