[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3590?page=c...
]
Julien roche commented on HHH-3590:
-----------------------------------
Hi guys,
I've got a similar problem with a bulk insert in HQL :
I've got a joined table. The parent is JoinedEntityA (which is abstract and has got
the version column), JoinedEntityB and JoinedEntity inherit from JoinedEntityA.
I want to replace some JoinedEntityB with JoinedEntityC, I will execute the following code
:
Session session = sessionFactory.getCurrentSession();
session.createQuery("insert into JoinedEntityC(number, id) select 5, id from
JoinedEntityB").executeUpdate();
session.createSQLQuery("delete from JoinedEntityB");
However, the following exception will be raised:
org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at ...
...
Caused by: java.sql.SQLException: Column not found: VERSION in statement [insert into
JoinedEntityC ( version, number ) select ?, 5 as col_0_0_ from JoinedEntityB joinedenti0_
inner join JoinedEntityA joinedenti0_1_ on joinedenti0_.id=joinedenti0_1_.id]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at ...
...
I find a 'workaround' : in the class org.hibernate.hql.ast.HqlSqlWalker, into the
postProcessInsert method, I've inserted the following code:
final boolean includeVersionProperty = persister.isVersioned() &&
!insertStatement.getIntoClause().isExplicitVersionInsertion() &&
persister.isVersionPropertyInsertable();
/*--- Start Fix ---*/
Boolean versionColumnOnTable = true;
if(persister instanceof JoinedSubclassEntityPersister){
// the version column is on this table or on parents ?
// maybe we must override isVersionPropertyInsertable into
// JoinedSubclassEntityPersister to return false ?
versionColumnOnTable = ((JoinedSubclassEntityPersister) persister).getPropertyTableName(
persister.getPropertyNames()[persister.getVersionProperty()]).equalsIgnoreCase(persister.getTableName());
}
/*--- End Fix ---*/
if ( includeVersionProperty && versionColumnOnTable) {
...
I don't find a good way to check if the version column is on the current table or on
the parent table. Maybe there are some methods, but I didn't find them.
An Eclipse project with the error is attached with this issue and an other Eclipse project
with the 'patch'.
Warning : that's solved only the insert case, not the update.
Having @version in Parent causes wrong HQL update when updating
subclass in Joined Subclass Inheritance Strategy.
-----------------------------------------------------------------------------------------------------------------
Key: HHH-3590
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3590
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.1
Environment: Java 1.5 , Oracle 10g , Hibernate 3.3.1.GA
Reporter: Rachit
Priority: Blocker
A very simple joined subclass strategy implemented.
2 classes: Employee(parent/superclass) and Person( child/subclass)
Employee has @Version defined on column ROW_VERSION and Person extends Employee using
Joined Inheritance Strategy. Person has PERSON_ID as PK and Employee has EMPLOYEE_ID as
PK. I also have @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName =
"EMPLOYEE_ID") for obvious reason.
Now if I update any attribute in Child class i.e Person.setVIPFlag("Y") ,
hibernate fires an update query on Parent entity with wrong column name in hql. In this
case the query would be "update EMPLOYEE set ROW_VERSION=? where PERSON_ID=? and
ROW_VERSION=?". This query fails as EMPLOYEE does not have PERSON_ID.
The moment I remove @Version annotation from Parent(Employee) class, there is no update (
as expected ) and hence no error, but this is not an acceptable solution.
Thanking in anticipation.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira