[Hibernate-JIRA] Created: (HHH-3836) composite-element with null columns in map is ignored
by Benoit Goudreault-Emond (JIRA)
composite-element with null columns in map is ignored
-----------------------------------------------------
Key: HHH-3836
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3836
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.SP1
Environment: 3.3.0 SP1, noticed with Oracle and H2 but probably happens with all databases
Reporter: Benoit Goudreault-Emond
Attachments: patate.zip
When a composite element with all properties set to NULL is inserted in a map of the said composite element, the data gets inserted to the database but is never retreived when reloading the entity.
For instance, with an entity
@Entity
public class TestEntity {
@Id
private int id;
@CollectionOfElements
private Map<String, AccessPeriod> roleAccesses = new HashMap<String, AccessPeriod>();
// boilerplate getters/setters/etc omitted
}
And AccessPeriod being
@Embeddable
public class AccessPeriod {
public Date startDate;
public Date endDate;
}
If you insert in the map an AccessPeriod with both startDate and endDate set to null and persist the TestEntity,
an entry is inserted in the auxiliary table, but when getting the TestEntity back, the map is empty.
You get the same problem with a mapping file.
This used to work in Hibernate 2.1--I found this out while porting some code to 3.3.
See the attached example. You'll need to include Hibernate and h2 (com.h2database:h2 1.0.20061217) on your classpath to run it with the given jdbc.properties, but feel free to change it.
--
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, 3 months
[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, 3 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, 3 months
[Hibernate-JIRA] Created: (ANN-814) OneToOne Unidirectional Support
by Rachit (JIRA)
OneToOne Unidirectional Support
-------------------------------
Key: ANN-814
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-814
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.4.0.GA
Environment: Oracle 10g, Java 1.5
Reporter: Rachit
Priority: Blocker
I tried hard for unidirectional OneToOne mapping as below:
@Entity
@Table(name = "PARTY")
public class Party{
private Person person;
private String key;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL,)
@PrimaryKeyJoinColumn(name = "PARTY_ID", referencedColumnName = "PERSON_PARTY_ID")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "PARTY_ID", nullable = false)
public String getKey() {
return key;
}
private void setKey(String key) {
this.key = key;
}
}
and it is one-to-one mapped to Person as:
@Entity(name = "Person")
@Table(name = "PERSON")
public class Person {
private String key;
@Id
@Column(name = "PERSON_PARTY_ID")
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
Now in Person, I deliberately dont have sysUUID as generated as then it generates a unique value for person and the association gets lost. With this mapping hibernate throws the following exception :
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): Person.
I read and saw constrained="true" being used in mapping files, which I couldnt use as there is no attribute like it in OneToOne annotation.
Please help me out on this
--
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