[Hibernate-JIRA] Created: (HHH-2955) Unnecessary version updates in two cases.
by Sławomir Wojtasiak (JIRA)
Unnecessary version updates in two cases.
-----------------------------------------
Key: HHH-2955
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2955
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5
Environment: JDK 5.0
Reporter: Sławomir Wojtasiak
Attachments: HibernateTest.zip
I found two situations where hibernate generates unnecessary version updates. Let's illustrate it with a simple example:
Session session = SessionFactory.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
Article a = new Article();
a.setName( "atricle" );
*********************************************
*** Quantity is the owner of the relation ***
*********************************************
Quantity q = new Quantity();
q.setName( "quantity" );
q.setArticle( a );
a.getQuantities().add( q );
session.persist( a );
session.flush();
***** Hibernate generates following SQLs *****
Hibernate: select nextval ('hibernate_sequence')
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into Article (name, version, id) values (?, ?, ?)
Hibernate: insert into Quantity (article_id, name, version, id) values (?, ?, ?, ?)
**********************************************
a.getQuantities().clear();
session.flush();
*** Hibernate generates following SQLs ***
Hibernate: update Article set name=?, version=? where id=? and version=?
This update of version field is performed because collection of quantities is marked as dirty, but Article entity is not relation owner so nothing change in database after this clear. Should it works like this? It looks like a bug because database remain unchanged so version changing is unnecessary in my opinion.
******************************************
session.clear();
**** SECOND PROBLEM ***
Now I generate true copy of persisted objects.
Notice that I use HashSet instead of PersistSet which was set during persist operation. This operation is similar to merging objects prepared by SOAP, during communication with remote client for example.
***********************
Article a1 = new Article();
a1.setId( a.getId() );
a1.setName( a.getName() );
a1.setVersion( a.getVersion() );
Quantity q1 = new Quantity();
q1.setArticle( a1 );
q1.setName( q.getName() );
q1.setVersion( q.getVersion() );
q1.setId( q.getId() );
a1.getQuantities().add( q1 );
a1 = (Article)session.merge( a1 );
session.flush();
***** This operation generates following SQLs *****
Hibernate: select article0_.id as id0_1_, article0_.name as name0_1_, article0_.version as version0_1_, quantities1_.article_id as article4_3_, quantities1_.id as id3_, quantities1_.id as id1_0_, quantities1_.article_id as article4_1_0_, quantities1_.name as name1_0_, quantities1_.version as version1_0_ from Article article0_ left outer join Quantity quantities1_ on article0_.id=quantities1_.article_id where article0_.id=?
Hibernate: update Article set name=?, version=? where id=? and version=?
It looks like problem is located in replaceElements() method of CollectgionType class (or somewhere near it). Maybe I'm wrong but this collection was checked for changes during merge operation (See this select above.) so why it remains dirty if it contains the same data as database?. I checked this issue on other JPA implementations (OpenJPA for example) and version is not incremented after similar merge operation.
*****************************************************
transaction.rollback();
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (HHH-3051) NPE while query.list on a Native SQL, using L2 cache
by Amit Kapoor (JIRA)
NPE while query.list on a Native SQL, using L2 cache
----------------------------------------------------
Key: HHH-3051
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3051
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5
Environment: Hibernate 3.2.5ga
Database Oracle 9i
Jdk - 1.4.2_13
EHCache 1.2.3 / OsCache 2.1 both
Reporter: Amit Kapoor
I get an NPE when i try to execute a native query.
Below is the excerpt of the code that throws NPE:
String sqlQuery = "select emp_id, emp_first_name from employee_mt";
SQLQuery query = session.createSQLQuery(sqlQuery);
query.setCacheable(true).setCacheRegion("TEST_REGION");
query.addScalar("emp_id");
query.addScalar("emp_first_name");
List list = query.list();
query.list() throws the following NPE:
java.lang.NullPointerException
at org.hibernate.type.TypeFactory.disassemble(TypeFactory.java:451)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2194)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2138)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at poc.hibernate.caching.QueryCaching.fireNativeSql(QueryCaching.java:112)
at poc.hibernate.caching.QueryCaching.fireQuery(QueryCaching.java:38)
at poc.hibernate.caching.QueryCaching.main(QueryCaching.java:27)
I tried tracing through the Hibernate code code and saw that the types[] in the at the time of execution of types[i].disassemble( row[i], session, owner ) (TypeFactory.disassemble()) was holding both the types as null.
However before reaching that piece of code CustomLoader.autoDiscoverTypes(resultset) had already resolved the resultTypes to appropriate values.
Hope this helps.
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (HHH-2225) NPE when eager fetching joined component with native SQL query
by Christian Bauer (JIRA)
NPE when eager fetching joined component with native SQL query
--------------------------------------------------------------
Key: HHH-2225
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2225
Project: Hibernate3
Type: Bug
Components: query-sql
Versions: 3.2.0.ga
Reporter: Christian Bauer
Priority: Minor
Item -> many-to-one -> User -> joined component -> billingAddress
This:
result = session.createSQLQuery("select {i.*}, {u.*}, {ba.*} from ITEM i" +
" join USERS u on i.SELLER_ID = u.USER_ID" +
" left join BILLING_ADDRESS ba on u.USER_ID = ba.USER_ID" +
" where u.USERNAME = :uname")
.addEntity("i", Item.class)
.addJoin("u", "i.seller")
.addJoin("ba", "u.billingAddress")
fails with:
java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:37)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:283)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:129)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (EJB-385) JPA method of merge failed to insert deleted records from database
by Hari (JIRA)
JPA method of merge failed to insert deleted records from database
-------------------------------------------------------------------
Key: EJB-385
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-385
Project: Hibernate Entity Manager
Issue Type: Improvement
Components: EntityManager
Affects Versions: 3.2.0.ga
Environment: 3.2.6.ga, Weblogic,JPA, Windows
Reporter: Hari
The following is my requirement.
Suppose i have a record in database with id say, 12.
i have retrieved this using a JPQL query and convert it into a transfer object ,done some processing and going to remerge this after converting it to a new entity but the id set in the new entity is same as old one ie 12.
Now just before calling entityManger.merge i have deleted the record with id 12 from database.
The issue is the merge opeartion is not inserting the record in database at all.
But if the id set in the entity is one which is never occured in the database,the merge operation will insert the record with the id set from teh application.
Is there any work around/fix for this issue.
Regards
Harikrishnan R
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (HHH-3459) NullPointerException in Formatter.isFunctionName with certain SQL when pretty format is used
by Scott Feldstein (JIRA)
NullPointerException in Formatter.isFunctionName with certain SQL when pretty format is used
--------------------------------------------------------------------------------------------
Key: HHH-3459
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3459
Project: Hibernate3
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.6
Reporter: Scott Feldstein
A NullPointerException is thrown when hibernate.show_sql=true && hibernate.format_sql=true while exec'ing sql with quotes around the stmt:
(taken from an embedded groovy script)
---------
def sess = getSession()
def HQL = """
(select count(*) from TABLE)
"""
sess
.createSQLQuery(HQL)
.list()
------------
This is valid SQL and is typically used in my app as such:
(select count(*) from TABLE1) UNION ALL (select count(*) from TABLE2) ...
Here is the stack trace in hibernate:
java.lang.NullPointerException
at org.hibernate.pretty.Formatter.isFunctionName(Formatter.java:342)
at org.hibernate.pretty.Formatter.openParen(Formatter.java:323)
at org.hibernate.pretty.Formatter.format(Formatter.java:134)
at org.hibernate.jdbc.AbstractBatcher.format(AbstractBatcher.java:410)
at org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:404)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:482)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (EJB-364) Composite PK and @GeneratedValue
by Radosław Smogura (JIRA)
Composite PK and @GeneratedValue
--------------------------------
Key: EJB-364
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-364
Project: Hibernate Entity Manager
Issue Type: Bug
Affects Versions: 3.3.2.GA
Environment: Hibernate 3.2.6
Glassfish
PostgreSQL
Reporter: Radosław Smogura
Priority: Critical
[code]
For class like this
@Entity
@IdClass(FooId.class)
/* Seq / Table generator */
public class Foo {
int id1;
int id2;
@Id
public getId1() {
return id1;
}
public setId1(....);
@Id
@GeneratedValue(strategy=AUTO/IDENTITY/SEQUENCE/TABLE)
public int getId2() {
return id2;
}
public void setId2(.....);
}
[/code]
Id1 is set manully, but id2 is unchanged i this situation hibernate doesn't generates PK and tries to insert NULL causing error.
Specification requires assigning of generated value with @Id properties. Part 2.4.1 defines two types of PKs simple and composite and part 9.1.9 says about PKs in generally. (SEQ or IDENTITY is specification depended, but PostgreSQL support it and Hibernate should support it too).
--
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
13 years, 4 months
[Hibernate-JIRA] Created: (HHH-3028) Memory consumption when query cache is enabled
by Markus Heiden (JIRA)
Memory consumption when query cache is enabled
----------------------------------------------
Key: HHH-3028
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3028
Project: Hibernate3
Issue Type: Bug
Components: caching (L2), core
Affects Versions: 3.2.5
Environment: Hibernate 3.2.5, Oracle 9i
Reporter: Markus Heiden
As discussed in the hibernate-dev mailing list from 9.11.2007 to 12.11.2007 this bug describes a memory consumption issue which is located in ActionQueue/EntityAction.
Some snippets from ActionQueue:
private ArrayList executions;
public void execute(Executable executable) {
final boolean lockQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();
if ( executable.hasAfterTransactionCompletion() || lockQueryCache ) {
executions.add( executable );
}
...
}
This code leads to a kind of memory leak, because if the "executable" is added to "executions", the related entity which is referenced from the "executable" is prevented from being garbage collected until the transaction ends. So if one needs to insert large amounts of transient objects in one transaction, there is no chance to get rid of the inserted objects by flushing and evicting them, if e.g. the query cache is enabled.
One solution to this problem might be to rework the above "if" condition to only add objects to "executions" if this is really needed. The problem is to determine when it is really needed.
Some snippets from EntityAction (which implements Executable):
private final Object instance;
public final Serializable getId() {
if ( id instanceof DelayedPostInsertIdentifier ) {
return session.getPersistenceContext().getEntry( instance ).getId();
}
return id;
}
public final Object getInstance() {
return instance;
}
Another solution might be to set the reference to the related entity (field "instance" in EntityAction) to null after flushing. This does not prevent "executions" from being filled, but the related entities might be garbage collected and so the memory consumption is acceptable. The problem is that subclasses of EntityAction use the "instance" field for post transaction work.
The are currently two workarounds to this problems:
1) To always disable the query cache
2) To use shorter transactions
Workaround 1 is not really acceptable, because it prohibits the use of a very useful feature.
Workaround 2 is sometimes acceptable but not wanted in most cases, because it breaks transactional safety.
--
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
13 years, 4 months