[Hibernate-JIRA] Created: (ANN-846) Infinite loop occurs while doing findById on a Parent domain Object having OneToMany relationship with child domain with composite primary key
by RAMESH BABU NL (JIRA)
Infinite loop occurs while doing findById on a Parent domain Object having OneToMany relationship with child domain with composite primary key
----------------------------------------------------------------------------------------------------------------------------------------------
Key: ANN-846
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-846
Project: Hibernate Annotations
Issue Type: Improvement
Affects Versions: 3.4.0.GA
Environment: Hibernate Annotations 3.4.0.GA, HSqlDB and Oracle
Reporter: RAMESH BABU NL
Attachments: Organization.java, OrganizationApplications.java, OrganizationApplicationsPK.java
We are using Hibernate annotations version 3.4.0.G.A
We are establishing a OneToMany relationship using the annotation @OnetoMany for a Parent and Child domain objects
where the child domain has a composite primary key.
We have two domain objects
Organization [Parent]
OrganizationApplications [Child]
We want to have a OnetoMany relationship between Organization and OrganizationApplications.
As shown below OrganizationApplications contains a composite primary key, of two columns(Organization Id, ApplicationId[foreignkey from other table called APPLICATIONS])
Organizations.java
-------------------
@OneToMany(targetEntity=gov.osc.enrollment.backend.domain.OrganizationApplications.class, cascade=CascadeType.ALL, fetch = FetchType.EAGER,
mappedBy="id.organization")
private Set<OrganizationApplications> organizationApps = new HashSet<OrganizationApplications>();
OrganizationApplications.java
---------------------------------------------------------------------
public class OrganizationApplications extends EnvelopeInfo implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private OrganizationApplicationsPK id;
public OrganizationApplicationsPK getId() {
return id;
}
public void setId(OrganizationApplicationsPK id) {
this.id = id;
}
OrganizationApplicationsPK.java
---------------------------------------------------------------------
@Embeddable
public class OrganizationApplicationsPK implements Serializable {
private static final Long serialVersionUID = 1L;
public OrganizationApplicationsPK() {
super();
}
@ManyToOne
@JoinColumn(name="APPLICATION_ID",nullable=false)
private Applications application;
@ManyToOne(targetEntity=gov.osc.enrollment.backend.domain.Organization.class, cascade=CascadeType.ALL)
@JoinColumn(name="ORGANIZATION_ID", referencedColumnName="ORGANIZATION_ID", nullable=false, insertable=true, updatable=true)
private Organization organization;
public Applications getApplication() {
return application;
}
public void setApplication(Applications application) {
this.application = application;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if ( ! (o instanceof OrganizationApplicationsPK)) {
return false;
}
OrganizationApplicationsPK other = (OrganizationApplicationsPK) o;
return (this.getOrganization().getId() == other.getOrganization().getId())
&& (this.getApplication().getId() == other.getApplication().getId());
}
@Override
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + ((int) (this.getOrganization().getId() ^ (this.getOrganization().getId() >>> 32)));
hash = hash * prime + ((int) (this.getApplication().getId() ^ (this.getApplication().getId() >>> 32)));
return hash;
}
}
Please see the attached java files for complete code and also the exception stack trace.
Questions:
1. When we do a findById query on Organization table the system goes into infinite loop and never gets out .
How ever we are able to insert a record in Organization and its child OrganizationApplications.
2. In the Organization.java domain, if you notice we are using mappedby="id.organization". Is this a valid mapping ?
If not why does this parameter work for insert and not for a entityManager.findById, doing so leads to infinite loop.
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-5135) Prefix is missed in HQL query for property mapped to column 'TO_DATE' on Oracle 10g
by Vladimir Ivanov (JIRA)
Prefix is missed in HQL query for property mapped to column 'TO_DATE' on Oracle 10g
-----------------------------------------------------------------------------------
Key: HHH-5135
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5135
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.1, 3.5.0-Final
Environment: Hibernate 3.5.1, Oracle 10.2.0.1.0
Reporter: Vladimir Ivanov
Attachments: test_case.zip
I have entity 'Period' with property 'toDate' mapped to database column with name 'TO_DATE' (Our database is Oracle 10g). When this entity is queried via HQL, prefix for this entity is missed. Following SQL query is produced:
Hibernate:
/*
from
Period p */ select
*
from
( select
period0_.ID as ID44_,
period0_.TXN_VER as TXN3_44_,
period0_.FROM_DATE as FROM4_44_,
TO_DATE as TO5_44_,
period0_.POSITION_MONTH as POSITION7_44_,
period0_.IS_CLOSE as IS12_44_,
period0_.IS_OPEN as IS13_44_,
period0_.DISC_TYPE as DISC2_44_
from
SOME_SCHEMA.T_PERIOD period0_ )
where
rownum <= ?
This leads to database error in case of more advanced query (with joins etc). For example, we have following error in production: java.sql.SQLException: ORA-00918: column ambiguously defined
Probably the reason of this behaviour is that Hibernate tries to interpret 'TO_DATE' as the name of SQL function.
In Hibernate 3.3.2.GA prefix is added correctly.
Domain object, DAO, Test and Hibernate configuration are in the attachment.
I used Spring framework to configure test.
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-5063) Projections that have aliases same as the property name result in invalid sql
by Shawn Clowater (JIRA)
Projections that have aliases same as the property name result in invalid sql
-----------------------------------------------------------------------------
Key: HHH-5063
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5063
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.5.0-Final
Reporter: Shawn Clowater
I have a criteria query that is using an AliasToBeanTransformer that I'm using to selectively populate some of the properties. It appears that the transformer requires the alias values to match the properties of your bean so that it can call the setters via reflection.
The code snippet is similar to the following
return (List<DataProvider>) session.createCriteria(DataProvider.class)
.setProjection(Projections.projectionList()
.add(Projections.property("dataProviderId), "dataProviderId")
.add(Projections.property("uuid"), "uuid")
.add(Projections.property("name"), "name")
.add(Projections.property("dataProviderGroup"), "dataProviderGroup")
.add(Projections.property("verifiedFlg"), "verifiedFlg")
)
.setResultTransformer(new AliasToBeanResultTransformer(DataProvider.class))
.addOrder(Order.asc("name"))
.list();
And is resulting in the following SQL
select y0_ as y0_, y1_ as y1_, y2_ as y2_, y3_ as y3_, y4_ as y4_ from DATA_PROVIDER this_ order by y2_ asc
I can assure you that my column names are not y0_, etc.
This worked in 3.3.2 and I am suspecting it might be due to the change for HHH-1088. If I don't specify the alias or even change the value then it will produce a valid query it just won't populate by bean correctly.
i.e. if I append anything to the end of the first alias (i.e. "hi") results in:
select this_.DATA_PROVIDER_ID as y0_, y1_ as y1_, y2_ as y2_, y3_ as y3_, y4_ as y4_ from DATA_PROVIDER this_ order by y2_ asc
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-3884) NPE with mutable Natuarl Id's
by Michael Kopp (JIRA)
NPE with mutable Natuarl Id's
-----------------------------
Key: HHH-3884
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3884
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Reporter: Michael Kopp
When saving an entity with a mutable natural id hibernate throws the following NPE.
java.lang.NullPointerException
at org.hibernate.engine.StatefulPersistenceContext.getNaturalIdSnapshot(StatefulPersistenceContext.java:267)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:78)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:162)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
I checked the code and found the reason:
- getNaturalIdSnapshot calls getDatabaseSnapshot and checks the result for NO_ROW but not for null
- getDatabaseSnapshot will never return NO_ROW but null if nothing was found
hence getNaturalIdSnapshot will produce a NPE if the entity is not in the database already.
the fix is simple:
change:
Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
if ( entitySnapshot == NO_ROW ) {
return null;
}
to
Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
if ( entitySnapshot == null ) {
return null;
}
This is still there in trunk as well!
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-4971) Findbugs Warnings
by Marco Tulio Valente (JIRA)
Findbugs Warnings
-----------------
Key: HHH-4971
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4971
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0.Beta-1
Reporter: Marco Tulio Valente
Priority: Minor
Dear all,
We are conducting a study about the relevance of the warnings reported by the FindBugs tool when executed over several open-source systems.
Particularly, in the case of Hibernate, we would like to confirm the relevance of the following warning reported by the tool (for version 3.5.0.beta1):
Location: org.hibernate.engine.StatefulPersistenceContext getNaturalIdSnapshot - Line: 298
Warning: Using pointer equality to compare different types. The method uses using pointer equality to compare two references that seem to be of different types. The result of this comparison will always be false at runtime.
Since this warning seemed relevant to us, we would like to confirm our classification with Hibernate's developers.
Best regards,
Marco Tulio Valente
Brazil
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-2041) Update with unaltered natural-id fails
by Jim Pease (JIRA)
Update with unaltered natural-id fails
--------------------------------------
Key: HHH-2041
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2041
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.3
Environment: hibernate-3.1.3, mysql-4.1.12
Reporter: Jim Pease
This may be a duplicate of http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574.
Getting following error:
caused by: org.hibernate.HibernateException: immutable natural identifier of an instance of edu.syr.lsb.gmt.impl.LinkImpl was altered
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:80)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:155)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
...
This is occurring without modifications to the natural identifier, which is mapped as follows:
<natural-id>
<property name="activityRef" column="ACTIVITY_REF" length="255" not-null="true" />
<many-to-one name="goal" class="GoalImpl" column="GOAL_ID" not-null="true" cascade="none" />
</natural-id>
--
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
14 years, 5 months
[Hibernate-JIRA] Created: (HHH-5053) Duplicate primary keys when using the SEQUENCE strategy due to underlying sequence not being updated when the SequenceGenerator's allocatedSize is greater than 1
by atomicknight (JIRA)
Duplicate primary keys when using the SEQUENCE strategy due to underlying sequence not being updated when the SequenceGenerator's allocatedSize is greater than 1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-5053
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5053
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0-CR-2
Environment: Hibernate 3.5.0-CR-2
PostgreSQL 8.4.1 (JDBC driver 8.4-701 JDBC4)
Glassfish v3 (build 74.2)
JDK 1.6.0_18
Reporter: atomicknight
Attachments: jpa-test.war, table1.sql
When the SequenceGenerator's allocatedSize is greater than 1, the underlying sequence associated with the table doesn't ever seem to be updated by Hibernate except on application startup. The test case uses an allocatedSize of 3, corresponding to an increment value of 3 in the underlying sequence.
Here's how to use the test case (requires EJB 3.1):
1) Set up the database using the attached SQL dump, then load the application
2) Access the test page via http://localhost:8080/jpa-test/test. You should see a page with the word "Done!"
3) Undeploy and redeploy the application
4) Access the test page again. You should encounter an error page indicating that the transaction was aborted.
Here's what I observed at the database level while following the above steps:
1) Sequence is created with a start value of 1 and increment value of 3.
2) Hibernate increments the sequence to 4. The application then inserts rows with IDs 12-31.
3) No change - the sequence still has a value of 4.
4) Hibernate increments the sequence to 7. The application attempts to insert a row with ID 21, but fails because the ID was already used in step 2.
Setting the SequenceGenerator's allocatedSize to 1 as well as changing the increment value of the sequence to 1 gives the correct behavior.
--
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
14 years, 5 months