[Hibernate-JIRA] Created: (HHH-2007) Hibernate doesn't support optional one-to-one associations
by Andrei Iltchenko (JIRA)
Hibernate doesn't support optional one-to-one associations
----------------------------------------------------------
Key: HHH-2007
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2007
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.cr2
Reporter: Andrei Iltchenko
Hibernate doesn't properly support optional one-to-one associations, e.g. Person (0..1) -- (0..1) Passport.
The Hibernate books and reference all talk of two ways of mapping one-to-one associations:
1. using a many-to-one fk association with a unique constraint on the fk;
2. using a pk association.
the trouble with both of them is that they enforce the mandatory property of an association end, which sometimes is not desirable. The first way enforces the mandatory property with the uniqueness constraint on the fk, the other by using the fact that one table's pk is its fk.
I tried to see if I could adapt the 1st way of representing one-to-ones to
support optional association ends. What I did was simply remove the unique and not null constrains from DDL generated (without removing it it would be impossible to have a Person record that doesn't reference a Passport record):
from
CREATE TABLE Person (
PassUniqueId VARCHAR (32) NOT NULL,
version INTEGER NOT NULL,
uniqueId VARCHAR (32) NOT NULL,
name VARCHAR (40) NULL,
PRIMARY KEY (uniqueId),
UNIQUE(PassUniqueId),
FOREIGN KEY (PassUniqueId) REFERENCES Passport (uniqueId)
);
to
CREATE TABLE Person (
PassUniqueId VARCHAR (32) NULL,
version INTEGER NOT NULL,
uniqueId VARCHAR (32) NOT NULL,
name VARCHAR (40) NULL,
PRIMARY KEY (uniqueId),
FOREIGN KEY (PassUniqueId) REFERENCES Passport (uniqueId)
);
but leave the uniqueness attribute in the mapping file:
<many-to-one
name="pass"
class="application.business.logic.Passport"
cascade="save-update,merge"
unique="true"
>
<column name="PassUniqueId"/>
</many-to-one>
The resulting solution worked fine and I was able to create instances of Person not linked to a Passport. However Hibernate didn't succed in keeping the association from degrading into a many-to-one. It enabled me to create two Persons linked with the same Passport:
PASSUNIQUEID | VIRSION | UNIQUEID | Name
================================================
0d8b3919fffff | 1 | 0d5fb1dcfff | John
0d8b3919fffff | 0 | 10fd07bdfff | Sam
A subsequent attempt at retrieving such Persons with Hibernate failed:
org.hibernate.HibernateException: More than one row with the given identifier was found: 0d8b3919ffffffd60151e135b6da0164, for class: application.business.logic.Passport.
Hibernate should be able to impose the single end property of such associations without relying on the underlying RDBMS engine and never allow them to degrade to many-to-ones.
--
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, 8 months
[Hibernate-JIRA] Created: (HHH-5675) Using compound primary key throws SQLException
by Ralf Pöhlmann (JIRA)
Using compound primary key throws SQLException
----------------------------------------------
Key: HHH-5675
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5675
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0, 3.6.0.CR2, 3.6.0.CR1, 3.5.6, 3.6.0.Beta4, 3.6.0.Beta3, 3.5.5, 3.6.0.Beta2, 3.6.0.Beta1, 3.5.4, 3.5.3, 3.5.2, 3.5.1, 3.5.0-Final
Environment: Hibernate 3.6.0, MySql
Reporter: Ralf Pöhlmann
Priority: Critical
Using compound primary keys via @IdClass causes an exception when calling persist:
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [de.methodpark.stages.model.UserAssignment]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:258)
Same code works when switching JPA provider to EclipseLink.
@Entity
@Table(name = "user_assignment")
@IdClass(value = UserAssignmentId.class)
public class UserAssignment implements Serializable {
@Id
private Long userId;
@Id
private Long elementId;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "element_id", referencedColumnName = "id")
private Element element;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
}
public class UserAssignmentId implements Serializable {
public UserAssignmentId() { }
@Column(name = "user_id", insertable = false, updatable = false)
public Long userId;
@Column(name = "element_id", insertable = false, updatable = false)
public Long elementId;
}
--
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, 8 months
[Hibernate-JIRA] Created: (HHH-5674) FilterOverrides Annotation
by Kenton (JIRA)
FilterOverrides Annotation
--------------------------
Key: HHH-5674
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5674
Project: Hibernate Core
Issue Type: Sub-task
Components: annotations, core
Affects Versions: 3.5.6, 3.6.0.Beta4, 3.6.0.Beta3, 3.5.5, 3.6.0.Beta2, 3.6.0.Beta1, 3.5.4, 3.5.3, 3.5.2, 3.5.1, 3.5.0-Final
Environment: 3.5.3
Reporter: Kenton
Priority: Minor
Since Filters are now mapped in a @MappedSuperClass (ANN-594) a @FilterOverride/s should be considered. In the same way you need to rename column attributes (@AttributeOverrides) and associations (@AssociationOverrides) and you may need to do the same on Filter.
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-1614) parent element should accept access="field"
by Marcin Kobylarz (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1614?page=c... ]
Marcin Kobylarz commented on HHH-1614:
--------------------------------------
It's 2010, version 3.5.6 but this is still not working.
{code:title=exception|borderStyle=solid}
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122)
at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:75)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:73)
at org.hibernate.mapping.Component.buildType(Component.java:183)
at org.hibernate.mapping.Component.getType(Component.java:176)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:275)
at org.hibernate.mapping.Property.isValid(Property.java:217)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464)
at org.hibernate.mapping.RootClass.validate(RootClass.java:236)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1193)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1378)
{code}
> parent element should accept access="field"
> -------------------------------------------
>
> Key: HHH-1614
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1614
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Affects Versions: 3.0.5
> Reporter: Hontvári József
> Priority: Minor
>
> Currently one cannot specify access="field" in a Hibernate mapping file in the "parent" element of components. This means that JavaBean style setters and getters must be created even if all other fields are accessed directly by Hibernate, which doesn't look nice in the source.
--
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, 8 months
[Hibernate-JIRA] Created: (HHH-4618) Support pagination: total rows ignore limit
by Dave (JIRA)
Support pagination: total rows ignore limit
-------------------------------------------
Key: HHH-4618
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4618
Project: Hibernate Core
Issue Type: New Feature
Components: core
Environment: JBoss 5.1.0GA
Reporter: Dave
Limit is used for pagination, but total number of rows must be known to calculate page count.
Currently we have to use two queries:
1. select * from Student where age<30 limit 20;
2. select count(*) from Student where age<30;
For complex query with joins/huge tables, it can be a performance issue.
For Criteria API query with group by, there is no way to get row count, for example
criteria.setProjection(Projection.projectionList().add(Projections.groupProperty("name")).add(Projections.sum(score)));
Currently there is no way to get row count of this query using Criteria API.
For MYSQL, SQL_CALC_FOUND_ROWS and FOUND_ROWS() are used to get row count ignoring limit.
Pagination is used for all web application. Hibernate should support it in HQL and Criteria API.
--
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, 8 months