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!