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.  [ 3 posts ] 
Author Message
 Post subject: IDBAG semantics and Oracle9i
PostPosted: Tue Jun 06, 2006 9:25 am 
Newbie

Joined: Wed Jan 11, 2006 10:28 am
Posts: 19
Location: Fano, Italy
I have a strange problem with idbag semantics... i use the mapping document posted here (values with no type specified are simply strings), and with HSQLDB file database i don't have any problem.
Using Oracle9i, the code not works, and the problem is in the element tag of idbag semantics, that in oracle not supports references to custom objects (but with HSQLDB works well!).
Any suggestions?

Hibernate version: 3.1.2

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.terranova.metadata.support.DB_Group" table="DB_Group">
<id name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" />
<property name="description" not-null="true" />
<idbag name="users" lazy="true" table="GROUP_USERS">
<collection-id type="long" column="ID">
<generator class="sequence" />
</collection-id>
<key column="USER_ID" />
<element type="it.terranova.metadata.support.DB_User" column="users" />
</idbag>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.terranova.metadata.support.DB_User" table="DB_User">
<id name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" />
<property name="password" not-null="true" />
<property name="userPermissions" type="it.terranova.metadata.support.UserPermissionsTypeCode" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(group);
session.getTransaction().commit();

session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from DB_Group").list();
assertEquals(1, result.size());

Object obj = result.get(0);
assertTrue(obj instanceof DB_Group);
session.getTransaction().commit();


Full stack trace of any exception that occurs:
with HSQLDB no exceptions!
With Oracle9i:
15:21:14,702 WARN JDBCExceptionReporter:71 - SQL Error: 1401, SQLState: 23000
15:21:14,722 ERROR JDBCExceptionReporter:72 - ORA-01401: value too large for the column

15:21:14,722 WARN JDBCExceptionReporter:71 - SQL Error: 1401, SQLState: 23000
15:21:14,732 ERROR JDBCExceptionReporter:72 - ORA-01401: value too large for the column


Name and version of the database you are using: Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 10:11 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you're getting a "value too large for the column" error, you should be checking that the strings you're saving aren't longer than the size of your DB column. Perhaps HSQL handles it quietly (it's not a true SQL DB, after all), but if you try to put a 100 character string into a varchar(20) column, then real DBMSs will throw this sort of error. You should either use the length="?" attribute of property (that will cause silent truncation of too-long strings), or do the check manually in your java code ("if (str.length() > DB_FIELD_LENGTH) throw new IllegalArgumentException("String too long");", or similar).

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 2:21 am 
Newbie

Joined: Wed Jan 11, 2006 10:28 am
Posts: 19
Location: Fano, Italy
Thanks for the response but the problem is in the element tag of the idbag semantics.
I've fixed in oracle (and also in HSQLDB works well) using <many-to-many class="MyClass" Column="CName"> instead of element type=...> for non-value types.


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