-->
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: "Out of range value adjusted for column" with <
PostPosted: Fri Nov 04, 2005 1:23 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:
ACLEntry.hbm.xml
Code:
<class name="ACLEntry" table="V_ACLENTRIES" lazy="false">
        <composite-id name="id" class="ACLEntryKey">
           <key-property name="entityType" type="integer" column="entityType"/>
           <key-property name="entityID" type="integer" column="entityID"/>
           <key-property name="objectType" type="integer" column="objectType"/>
           <key-property name="objectID" type="integer" column="objectID"/>
        </composite-id>

        <property name="entityName" type="string" column="entityName" insert="false" update="false"/>
        <property name="accessLevel" column="accessLevel" type="integer" not-null="true"/>
        <property name="accessLevelString" column="accessLevelString" type="string" insert="false" update="false"/>
        <property name="readOnly" column="readOnly" type="boolean" not-null="true" />
       
        <sql-insert>
        insert into OBJECTSECURITY(entityType, entityID, objectType, objectID, accessLevel, readOnly)
        values(?, ?, ?, ?, ?, ?)
        </sql-insert>
       
    </class>



Code between sessionFactory.openSession() and session.close():
ACLEntryKey aek = new ACLEntryKey(1, 2, 2, 5);
ACLEntry a = new ACLEntry();
a.setId(aek);
a.setAccessLevel(-1);
a.setReadOnly(false);
s.save(a);
s.flush();

Full stack trace of any exception that occurs:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at HibernateTest.main(HibernateTest.java:37)
Caused by: java.sql.BatchUpdateException: Out of range value adjusted for column 'entityType' at row 1 at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:642)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 6 more
Exception in thread "main"

Name and version of the database you are using:MySQL 5.0

The generated SQL (show_sql=true):
insert into OBJECTSECURITY(entityType, entityID, objectType, objectID, accessLevel, readOnly)
values(?, ?, ?, ?, ?, ?)

Here's what I was trying to do with the above set-up:

ACLEntry is a class with a composite-id of class ACLEntryKey.

In my database, there is a table called OBJECTSECURITY which stores the fields entityType, entityID, objectType, objectID, accessLevel, readOnly (without the fields accessLevelString and entityName).
There is also a view called V_ACLEntries which joins OBJECTSECURITY table with some other tables in order to retrieve the complete information for ACLEntry.

Notice that I've linked the ACLEntry class to the view instead of a table. I've also set accessLevelString and entityName to not participate in inserts and updates as these are derived fields.

I had no problems with loads and select queries. No need for any extra work, since the view contains all the fields needed.

For inserts, updates, and deletes, I plan to override the default via <sql-insert>, <sql-update> and <sql-delete> tags to insert into the OBJECTSECURITY table instead.

Ran into the above problem when I was trying to do the <sql-insert>. Any ideas what's causing the exception?

Not sure if what I'm proposing here will work. Would welcome any suggestions for a better implementation!

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 1:29 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Just some more background...

I did consider using formulas for the 2 fields accessLevelString and entityName, but decided against it because of the complexity of the formula involved.

To get accessLevelString, I need 1 join, and to get entityName, I need a union of 2 statements with 1 join each. That's 2 sub-selects with joins and union in one select statement, and this gets called every time I load an object of this class!

That's why I thought using a view might be better, although unorthodox. Or is this commonly used?

Anyone has any comments on which of these 2 approaches is better?

Thanks!


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.