[Hibernate-JIRA] Created: (EJB-272) PostRemove being called before entity is actually deleted
by Paul (JIRA)
PostRemove being called before entity is actually deleted
---------------------------------------------------------
Key: EJB-272
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-272
Project: Hibernate Entity Manager
Type: Bug
Versions: 3.2.1
Environment: Hibernate 3.2.1GA Entity Manager
Hibernate core 3.2.2 GA
Oracle 9i
Windows XP professional service pack 2
No application server is being used.
Reporter: Paul
I have an EntityListener with a method annotated with postremove. It seems that the method is being called before the actual entity is deleted from the database. When configuring log4j with "debug" logging it appears that the method is being called after the PreparedStatement is created and configured but before executeUpdate() is called.
I see the following statements in my log file before my listener is called
14:06:27,024 DEBUG AbstractBatcher:476 - preparing statement
14:06:27,024 DEBUG IntegerType:133 - binding '59532' to parameter: 1
My listener is called next. Then, the prepared statement is executed.
This violates the EJB3 spec. The EJB3 spec states "The PostPersist and PostRemove methods will be invoked after the
database insert and delete operations respectively."
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HHH-3224) Invalid generated SQL for nested queries
by Adam Dyga (JIRA)
Invalid generated SQL for nested queries
----------------------------------------
Key: HHH-3224
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3224
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: MySQL
Reporter: Adam Dyga
I'm facing a problem with invalid generated SQL for nested queries.
I've the following class hierarchy (left only the most important fields for clarity):
//base class
class Asset {
String description; // <- field in base class
}
class ImageSet {
List<Wallpaper> wallpapers;
}
class Wallpaper extends Asset { // <- inherits from Asset
}
The HBM mappings:
<class name="com.company.Asset" table="Asset" abstract="true">
<property name="description" column="description" type="string" />
<id>...</id>
</class>
<class name="ImageSet" table="ImageSets">
<bag name="wallpapers" cascade="delete-orphan" inverse="true"
table="Wallpapers">
<key column="imageSetId" />
<one-to-many class="com.company.Wallpaper" />
</bag>
</class>
<joined-subclass name="com.company.Wallpaper"
extends="com.company.Asset" table="Wallpapers">
<key column="id" />
<many-to-one name="imageSet" column="imageSetId"
class="com.company.ImageSet" />
</joined-subclass>
When I try to execute the following HQL query:
select distinct imageSet from ImageSet imageSet where (select count(*) from imageSet.wallpapers w where w.description is not null) = size(imageSet.wallpapers)
I get the following SQL query:
select distinct imageset0_.id as id14_ from ImageSets imageset0_ where (select count(*) from Wallpapers wallpapers1_ where imageset0_.id=wallpapers1_.imageSetId and (wallpapers1_1_.description is not null)])=(select count(wallpapers2_.imageSetId) from Wallpapers wallpapers2_ inner join Asset wallpapers2_1_ on wallpapers2_.id=wallpapers2_1_.id where imageset0_.id=wallpapers2_.imageSetId)
The error message is
Unknown column 'wallpapers1_1_.description' in 'where clause'
which is right - note the missing wallpapers1_1_ alias which should be defined during inner join of the Wallpapers table with the base Asset table in the first nested query - just as it is done in the second nested query.
Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'wallpapers1_1_.description' in 'where clause'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HSEARCH-306) Problem with composite key
by Mohit Khopkar (JIRA)
Problem with composite key
--------------------------
Key: HSEARCH-306
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-306
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.1.0.CR1
Reporter: Mohit Khopkar
Attachments: hibernate jira.zip
When a composite key is used and more than one results are expected , the values passed to the query are not in a proper expected order.
In the below query the parameters passed are (A00, A00),(A00, 1),(2,5) ....instead of the correct order which should be (A00,1) ,(A00,2), (A00,5)
(I have omitted the select part)..
..
where ((this_.key_client, this_.key_identifier) in ((?, ?), (?, ?), (?, ?)))
I tried to debug this issue and found that in the class org.hibernate.criterion.InExpression, the method getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) has 2 for loops , one for types and other for values. I get 2 types CustomType and LongType and so for each type it retrieves the value and adds it in the list in the order A00,A00,A00,1,2,5
I have attached the source code for your reference.
For more information, refer to the below topic on the hibernate forums:
http://forums.hibernate.org/viewtopic.php?t=992121&sid=16e54abb3dbc45d314...
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HHH-3164) "id in ..." with EmbeddedId and criteria API
by Bartosz Jablonski (JIRA)
"id in ..." with EmbeddedId and criteria API
--------------------------------------------
Key: HHH-3164
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3164
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.6
Environment: hibrenate 3.2.5 hibernate-annotations 3.3.0, database - h2, postgresql, h2
Reporter: Bartosz Jablonski
Attachments: test.zip
This issue arised when I was debugging hibernate search, which wasn't retriving entities from query.
Problem is using query like 'entity.id in ...' with criteria api and embeddedId.
Let's say that we have classes:
@Entity
public class SomeEntity implements Serializable {
@Id
private SomeEntityId id;
(...)
}
@Embeddable
public class SomeEntityId implements Serializable {
private Integer id;
private Integer version;
(...)
}
In database there are rows:
(id,version)
1,11
1,12
10,21
10,22
10,23
Now I want to retrive rows with id (1,12) and (10,23) using Criteria API:
List ids = new ArrayList<SomeEntityId>(2);
ids.add( new SomeEntityId(1,12) );
ids.add( new SomeEntityId(10,23) );
Criteria criteria = session.createCriteria( SomeEntity.class );
Disjunction disjunction = Restrictions.disjunction();
disjunction.add( Restrictions.in( "id", ids ) );
criteria.add( Restrictions.in( "id", ids ) );
hibernate returns no rows, because it constructs query like this:
select this_.id as id0_0_, this_.version as version0_0_, this_.prop as prop0_0_ from SomeEntity this_ where (this_.id, this_.version) in ((1, 10), (12, 23))
instead of
select * from SomeEntity where (id, version) in ((1, 12), (10, 23))
As example I attached maven project which is using h2 database - just run class test.App
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HHH-2142) PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code
by Andrzej Miazga (JIRA)
PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code
--------------------------------------------------------------------------------------------------------
Key: HHH-2142
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2142
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.cr5
Reporter: Andrzej Miazga
Here is some code in Hibernate 3.2.0cr5 that may cause this behaviour. I'm not sure if this is a bug but it surely affects the client code.
AbstractPersistentCollection:
protected Object readElementByIndex(Object index) {
if (!initialized) {
...
return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
}
...
return UNKNOWN;
}
PersistentMap (extends AbstractPersistentCollection):
public Object put(Object key, Object value) {
if ( isPutQueueEnabled() ) {
Object old = readElementByIndex( key );
queueOperation( new Put( key, value, old ) );
return old;
}
...
So, there is a possibility to return UNKNOWN instance (MarkerObject) to the client code as the result of Map.put().
In version 3.1.3 this worked fine, but the implementation was different:
public Object put(Object key, Object value) {
Object old = isPutQueueEnabled() ?
readElementByIndex(key) : UNKNOWN;
if ( old==UNKNOWN ) {
write();
return map.put(key, value);
}
...
}
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HHH-3226) HQL/JPQL query with where clause expression involving mulitple correlated subqueries does not parse
by Bob Tiernay (JIRA)
HQL/JPQL query with where clause expression involving mulitple correlated subqueries does not parse
---------------------------------------------------------------------------------------------------
Key: HHH-3226
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3226
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.6
Reporter: Bob Tiernay
The following named query will not parse:
@NamedQuery(name = "Account.findTotalInactiveCount", query = "SELECT COUNT(a) FROM Account a WHERE a.status.name NOT IN ('nst', 'ncl') AND a.seed = FALSE AND (SELECT CURRENT_DATE - MAX(t.date) FROM Trade t WHERE a.id IN (t.purchaser.id, t.seller.id)) > 183 AND ((SELECT SUM(t1.asset.price.value * t1.numberOfUnits) FROM Trade t1 WHERE t1.purchaser.id = a.id) - (SELECT SUM(t2.totalPrice * t2.numberOfUnits) FROM Trade t2 WHERE t2.seller.id = a.id) + (SELECT SUM(gl.debit) - SUM(gl.credit) FROM GeneralLedger gl WHERE gl.glAccount.id = 15 AND gl.account.id = a.id)) > 150.00")
The error(s) issued from Hibernate are:
0 [main] ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected AST node: query
15 [main] ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected AST node: query
For readability, I have formatted the query:
SELECT COUNT(a)
FROM Account a
WHERE a.status.name NOT IN ('nst', 'ncl') AND
a.seed = FALSE AND
(
SELECT CURRENT_DATE - MAX(t.date)
FROM Trade t
WHERE a.id IN (t.purchaser.id, t.seller.id)
) > 183 AND
(
(SELECT SUM(t1.asset.price.value * t1.numberOfUnits)
FROM Trade t1
WHERE t1.purchaser.id = a.id) -
(SELECT SUM(t2.totalPrice * t2.numberOfUnits)
FROM Trade t2
WHERE t2.seller.id = a.id) +
(SELECT SUM(gl.debit) - SUM(gl.credit)
FROM GeneralLedger gl
WHERE gl.glAccount.id = 15 AND
gl.account.id = a.id)
) > 150.00
As an aside, I've tried reproducing this query using the Criteria API with no luck. There doesn't seem to be a way to combine the results of subqueries for comparison.
--
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
15 years, 1 month
[Hibernate-JIRA] Created: (HHH-2421) Cascading Delete In Wrong Order
by CannonBall (JIRA)
Cascading Delete In Wrong Order
-------------------------------
Key: HHH-2421
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2421
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Environment: Hibernate 3.2.1, Java5, MySQL 5 (InnoDB)
Reporter: CannonBall
Priority: Trivial
Mapping Document:
<hibernate-mapping>
<class name="scratchpad.hibernate.A">
<id name="id">
<generator class="increment"/>
</id>
<list name="bs" cascade="all,delete-orphan">
<key column="bId"/>
<list-index column="idx"/>
<one-to-many class="scratchpad.hibernate.B"/>
</list>
</class>
<class name="scratchpad.hibernate.B">
<id name="id">
<generator class="increment"/>
</id>
<many-to-one name="a" column="aId" insert="false" update="false"/>
<many-to-one name="c" column="cId" not-null="false"/>
</class>
<class name="scratchpad.hibernate.C">
<id name="id">
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
long id;
SessionFactory factory = new Configuration().configure()
.buildSessionFactory();
try {
Session s = factory.openSession();
try {
Transaction tx = s.beginTransaction();
try {
C c = new C();
s.save(c);
B b = new B();
b.setC(c);
A a = new A();
a.getBs().add(b);
s.save(a);
tx.commit();
id = b.getId();
} catch (Exception e) {
try {
tx.rollback();
} catch (Exception e2) {
// do nothing
}
throw e;
}
} finally {
s.close();
}
s = factory.openSession();
try {
Transaction tx = s.beginTransaction();
try {
A a = (A) s.load(A.class, id);
B b = a.getBs().get(0);
a.getBs().remove(b);
s.delete(b.getC());
tx.commit();
} catch (Exception e) {
try {
tx.rollback();
} catch (Exception e2) {
// do nothing
}
throw e;
}
} finally {
s.close();
}
} finally {
factory.close();
}
The generated SQL (show_sql=true):
Hibernate: select max(id) from C
Hibernate: select max(id) from A
Hibernate: select max(id) from B
Hibernate: insert into C (id) values (?)
Hibernate: insert into A (id) values (?)
Hibernate: insert into B (cId, id) values (?, ?)
Hibernate: update B set bId=?, idx=? where id=?
Hibernate: select a0_.id as id0_0_ from A a0_ where a0_.id=?
Hibernate: select bs0_.bId as bId1_, bs0_.id as id1_, bs0_.idx as idx1_, bs0_.id as id1_0_, bs0_.aId as aId1_0_, bs0_.cId as cId1_0_ from B bs0_ where bs0_.bId=?
Hibernate: select c0_.id as id2_0_ from C c0_ where c0_.id=?
Hibernate: update B set cId=? where id=?
Hibernate: update B set bId=null, idx=null where bId=?
Hibernate: delete from C where id=?
Hibernate: delete from B where id=?
When you have a collection that is mapped with a cascade of 'delete-orphan', when removing an entity from the collection, the corresponding orphan delete is scheduled at the end of the session's deletions queue. As you can see from my example above, when you have a relationship of A has a list of B's, B has a relationship with C, removing B from the A's list results in its deletion after C's deletion (despite the order of statements dictating C's deletion after B's). If I were to make B's relationship to C not-null, the above code would result in a FK constraint error as C would be removed before B.
You could force the correct removal of B before C with a manual delete of B like so:
A a = (A) s.load(A.class, id);
B b = a.getBs().get(0);
C c = b.getC();
a.getBs().remove(b);
s.delete(b);
s.delete(c);
--
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
15 years, 1 month