-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate2 mapping database view, how to?
PostPosted: Thu Feb 23, 2006 10:39 pm 
Newbie

Joined: Wed Feb 01, 2006 12:48 am
Posts: 2
I am using hibernate2.1.8 and DB2, and there are a lot of views in my database, I can generate the hbm by hibernate-extensions-2.1.3 like below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.database.ClassList" schema="DB2INST1" table="CLASS_LIST">
<property column="TERMS_ID" length="20" name="termsId" not-null="true" type="string"/>
<property column="COURSE_NAME" length="30" name="courseName" type="string"/>
<property column="COURSE_ID" length="6" name="courseId" type="string"/>
<property column="CLASSROOM" length="5" name="classroom" type="short"/>
<property column="CLASS_ID" length="10" name="classId" not-null="true" type="integer"/>
<property column="TIMETABLE" length="5" name="timetable" type="short"/>
<property column="WEEKNO" length="4" name="weekno" type="string"/>
<property column="REAL_STUDENTNUM" length="5" name="realStudentnum" type="short"/>
<property column="RESERVE_STUDENTNUM" length="5" name="reserveStudentnum" type="short"/>
<property column="STATUS" length="20" name="status" type="string"/>
<property column="CENTER_ID" length="8" name="centerId" type="string"/>
</class>
</hibernate-mapping>
as you can see, there isn't any <id> item, and I got the error "SEVERE: Error parsing XML: XML InputStream(20)"...
how to use database view? thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 10:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Make one or more (or all) properties the primary (composite) key in the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 11:01 pm 
Newbie

Joined: Wed Feb 01, 2006 12:48 am
Posts: 2
david wrote:
Make one or more (or all) properties the primary (composite) key in the mapping.


thank you for reply, but view hasn't a key, I try to make a key as below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.babycare.database">
<class
name="ClassList"
table="CLASS_LIST"
>
<id name="Id" type="integer" column="CLASS_ID">
<generator class="native"/>
</id>
<property column="TERMS_ID" name="termsId" type="string" />
<property column="COURSE_NAME" length="30" name="courseName" type="string"/>
<property column="COURSE_ID" length="6" name="courseId" type="string"/>
<property column="CLASSROOM" length="5" name="classroom" type="short"/>
<property column="TIMETABLE" length="5" name="timetable" type="short"/>
<property column="WEEKNO" length="4" name="weekno" type="string"/>
<property column="REAL_STUDENTNUM" length="5" name="realStudentnum" type="short"/>
<property column="RESERVE_STUDENTNUM" length="5" name="reserveStudentnum" type="short"/>
<property column="STATUS" length="20" name="status" type="string"/>
<property column="CENTER_ID" length="8" name="centerId" type="string"/>

</class>
</hibernate-mapping>
There isn't parse error this time, but another error as below:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.babycare.townsend.testdb.main(testdb.java:22)
Caused by: java.lang.RuntimeException: Exception building SessionFactory: could not instantiate id generator
at com.babycare.townsend.HibernateUtil.<clinit>(HibernateUtil.java:28)
... 1 more
will you please give me any advise?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 1:09 pm 
Newbie

Joined: Wed Sep 27, 2006 12:41 pm
Posts: 1
Location: Germany
Hi townsend,

david was right, just make some properties (that would in combination make each input to the view individual) to combinated key-properties.

Something like this:

<hibernate-mapping>
<class name="com.database.ClassList" schema="DB2INST1" table="CLASS_LIST">

<composite-id>

<key-property column="TERMS_ID" length="20" name="termsId" not-null="true" type="string"/>

<key-property column="COURSE_ID" length="6" name="courseId" type="string"/>

</composite-id>

<property column="COURSE_NAME" length="30" name="courseName" type="string"/>

....

</class>
</hibernate-mapping>


Luck
M.Faith


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.