[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
14 years, 2 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
14 years, 2 months
[Hibernate-JIRA] Created: (HSEARCH-528) MassIndexer attempts to index non-indexed subclasses of indexed types
by Sanne Grinovero (JIRA)
MassIndexer attempts to index non-indexed subclasses of indexed types
---------------------------------------------------------------------
Key: HSEARCH-528
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-528
Project: Hibernate Search
Issue Type: Bug
Affects Versions: 3.2.0.Final, 3.2.0.CR1, 3.2.0.Beta1
Reporter: Sanne Grinovero
Fix For: 3.3.0
quoting comments from HSEARCH-526:
j nadler :
{quote}Sanne,
I have @Indexed class Parent, @Indexed class Child1 extends Parent, @Indexed class Child2 extends Parent, unindexed class Child3 extends Parent.
I create an indexer fullTextEntityManager.createIndexer(Parent.class), it seems that it then fetches all Parent entities. This includes all Child3 entities but Child3 is not indexed. It seems like the MassIndexer attempts to index them anyway.
Best behavior might be to ignore these (explicitly check if the concrete subtype is @Indexed, skip that record if not, possibly log a warning) or as you say it could at least throw an error that makes it clear what the developer (me) did wrong.
Thanks!
{quote}
Emmanuel Bernard :
{quote}Ah, right. Sanne, you should use the same algorithm we use in the query building process to check the list of indexed subclasses to create the list of indexes to merge.{quote}
--
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, 3 months