[Hibernate-JIRA] Created: (HHH-7213) Hibernate throws a "MappingException: Repeated column in mapping for collection" on order columns also being a foreign key/relationship column
by Karsten Wutzke (JIRA)
Hibernate throws a "MappingException: Repeated column in mapping for collection" on order columns also being a foreign key/relationship column
----------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-7213
URL: https://hibernate.onjira.com/browse/HHH-7213
Project: Hibernate ORM
Issue Type: Bug
Affects Versions: 4.1.1
Reporter: Karsten Wutzke
I'm using an order column for an @OrderColumn which is also part of a foreign key like:
{code}@ManyToMany
@JoinTable(name = "GroupLinks", joinColumns = {@JoinColumn(name = "parent_round_id", referencedColumnName = "round_id"), @JoinColumn(name = "parent_ordinal_nbr", referencedColumnName = "ordinal_nbr")}, inverseJoinColumns = {@JoinColumn(name = "child_round_id", referencedColumnName = "round_id"), @JoinColumn(name = "child_ordinal_nbr", referencedColumnName = "ordinal_nbr")})
@OrderColumn(name = "child_ordinal_nbr")
private List<Group> children;{code}
As you can see the order column "child_ordinal_nbr" is also an FK (and PK) in the join table. However, this fails with a mapping exception:
{code}Caused by: org.hibernate.MappingException: Repeated column in mapping for collection: com.kawoolutions.bbstats.model.Group.parents column: parent_ordinal_nbr
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:340)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:363)
at org.hibernate.mapping.Collection.validate(Collection.java:320)
at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:89)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
... 9 more{code}
IMO there's no reason to assume the order column is not a foreign key column, too.
I've posted an extensive example over at stackoverflow.com:
http://stackoverflow.com/questions/9957247/is-manytomanymappedby-ordercol...
While the JPA spec is silent about this behavior there's no reason why the depicted scenario shouldn't be working.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 2 months
[Hibernate-JIRA] Created: (HHH-6473) Hibernate hbm2ddl doesn't create Indexes from @Index annotations on @ManyToMany relations
by Samuel Mendenhall (JIRA)
Hibernate hbm2ddl doesn't create Indexes from @Index annotations on @ManyToMany relations
-----------------------------------------------------------------------------------------
Key: HHH-6473
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6473
Project: Hibernate Core
Issue Type: New Feature
Components: annotations
Affects Versions: 4.0.0.Beta4
Reporter: Samuel Mendenhall
Fix For: 4.x
When generating the SQL schema with Hibernate using the hbm2ddl feature the generation of indexes on ManyToMany relationships like the following is not working:
@ManyToMany()
@JoinTable(name = "REL_FOO_BAR", joinColumns = @JoinColumn(name = "FOO_FK"), inverseJoinColumns = @JoinColumn(name = "BAR_FK"))
@Index(name = "FOO_BAR_IDX")
The created SQL schema doesn't include an index named USER_ROLES_IDX. With other relation types (ManyToOne, etc.) the index is created as expected.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 2 months
[Hibernate-JIRA] Created: (HHH-2223) BatchFetchQueue.getXXXBatch() cache check impeding batch fetching
by Joel Caplin (JIRA)
BatchFetchQueue.getXXXBatch() cache check impeding batch fetching
-----------------------------------------------------------------
Key: HHH-2223
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2223
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.ga
Environment: 3.2.0GA, Mac OS X/Solaris 10, Sybase 12.5/HSQLDB
Reporter: Joel Caplin
Priority: Minor
Attachments: testcase.tar
I have attached a test case which demonstrates the issue at hand by implementing a cheap data model: Pub >---|- Manager -|--< Employee
Pub and Employee are uncached; Manager is cached (tried under both Eh and the non-prod HashMap implementation). All associations are lazy. The test case has a default batch size of 10 and uses hsqldb to demonstrate the problem - which was diagnosed against Sybase.
When BatchFetchQueue.getXXXBatch() is invoked, it does not load any objects it finds in the second level cache - it merely acknowledges their presence by logging to INFO (isCached()). This in turn means that any child associations in that cached object will not have a proxy created for them.
Suppose we want to find all the employees of the pubs in our database. We choose to do this by loading all the Pubs ("FROM Pub") and calling thePub.getManager().getEmployees() iteratively.
When the managers are in the second level cache, Hibernate issues 11 select statements: one to load the pubs and one for each distinct manager.
When the Managers are not in the cache, Hibernate issues 3 select statements: one to load the pubs, one to load the managers and one to load the employees.
A solution might be to load the object from the cache instead of just ignoring 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
12 years, 2 months
[Hibernate-JIRA] Created: (HHH-6317) Retrieving
by Clint Popetz (JIRA)
Retrieving
-----------
Key: HHH-6317
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6317
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.6.5
Reporter: Clint Popetz
For the following mapping:
{code}
public class AnEntity extends HibernatePersistedObject {
@Id
@GeneratedValue
private Long id;
@OneToOne(optional=false,mappedBy="anEntity")
private TargetEntity target;
}
public class TargetEntity {
@Id
@GeneratedValue
private Long id;
@ManyToOne
private AnEntity anEntity;
}
{code}
and the following query:
{code}
AuditReaderFactory.get(em).createQuery().
forRevisionsOfEntity(AnEntity.class,false,false).
add(AuditEntity.id().eq(id)).addOrder(AuditEntity.revisionNumber().desc()).
setMaxResults(1).getSingleResult()
{code}
I get an NPE because the there is no EntityConfiguration for TargetEntity, as it is not audited:
{noformat}
java.lang.NullPointerException
at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:81)
at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
at org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:82)
at org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:118)
at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:100)
at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:135)
at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
{noformat}
--
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
12 years, 2 months
[Hibernate-JIRA] Created: (HHH-4591) Criteria.createAlias not working for key-many-to-one associations of a composite-id
by Luka (JIRA)
Criteria.createAlias not working for key-many-to-one associations of a composite-id
-----------------------------------------------------------------------------------
Key: HHH-4591
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4591
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.3.2, 3.2.7, 3.2.6
Environment: Hibernate 3.2.6.ga, 3.2.7.ga, 3.3.2.ga
Database: Oragle10g
Reporter: Luka
I'm trying to create an alias to apply a filter on a composite primary-key association, but I'm getting an invalid SQL generated by the ctiteria api: in the SQL there is the filter applied in the where, but the join for the alias is missing in the from.
Here is a sample of the problem:
Mappings (I stripped non relevant info):
TableOne.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TableOne" table="TABLE_ONE" dynamic-insert="false" dynamic-update="false">
<id name="idTableOne" type="java.lang.Long" unsaved-value="null">
<column name="ID_CONTRATTO"/>
<generator class="sequence">
<param name="sequence">S_TABLE_ONE</param>
</generator>
</id>
<set name="tableOneToTableTwo" order-by="ID_TABLE_ONE" lazy="true" fetch="select" inverse="true" cascade="none">
<key>
<column name="ID_TABLE_ONE"/>
</key>
<one-to-many class="TableOneToTableTwo"/>
</set>
</class>
</hibernate-mapping>
TableOneToTableTwo.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TableOneToTableTwo" table="TABLE_ONE_TO_TABLE_TWO" dynamic-insert="false" dynamic-update="false">
<composite-id name="tableOneToTableTwoPk" class="TableOneToTableTwoPK">
<key-many-to-one name="tableOne" class="TableOne" >
<column name="ID_TABLE_ONE"/>
</key-many-to-one>
<key-many-to-one name="tabelTwo" class="TabelTwo" >
<column name="ID_TABLE_TWO"/>
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
TabelTwo.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TabelTwo" table="TABLE_TWO" dynamic-insert="false" dynamic-update="false">
<id name="idTableTwo" type="java.lang.Long" unsaved-value="null">
<column name="ID_TABLE_TWO"/>
<generator class="sequence">
<param name="sequence">S_TABLE_TWO</param>
</generator>
</id>
<property name="codTabelTwo" type="java.lang.String">
<column name="COD_TABLE_TWO" not-null="true" unique="false"/>
</property>
</class>
</hibernate-mapping>
Code:
Criteria hibCrit = getSession().createCriteria(TableOne.class);
hibCrit.createAlias("tableOneToTableTwo", "tableOneToTableTwo");
hibCrit.createAlias("tableOneToTableTwo.tableOneToTableTwoPk.tabelTwo", "tabelTwo");
hibCrit.add(Restrictions.eq("tabelTwo.codTabelTwo", "AAA"));
hibCrit.list();
Generated SQL using Oracle10G dialect (I stripped columns in select):
SELECT [...]
FROM TABLE_ONE this_
INNER JOIN TABLE_ONE_TO_TABLE_TWO tabelTwoco1_ ON this_.ID_TABLE_ONE = tabelTwoco1_.ID_TABLE_ONE
WHERE tabelTwo2_.COD_TABLE_TWO = ?
The "tabelTwo2_" should be the sql alias for criteria alias "tabelTwo", but the table and the join are missing in the from...
I also tried using createCriteria:
Criteria hibCrit = getSession().createCriteria(TableOne.class);
hibCrit.createAlias("tableOneToTableTwo", "tableOneToTableTwo");
Criteria tableTwoCrit = hibCrit.createCriteria("tableOneToTableTwo.tableOneToTableTwoPk.tabelTwo", "tabelTwo");
tableTwoCrit.add(Restrictions.eq("tabelTwo.codTabelTwo", "AAA"));
hibCrit.list();
But i get the same sql query.
Also upgrading Hibernate result in the same 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
12 years, 2 months
[Hibernate-JIRA] Created: (HHH-7287) Problem in caching proper natural-id-values when obtaining result by naturalIdQuery
by Guenther Demetz (JIRA)
Problem in caching proper natural-id-values when obtaining result by naturalIdQuery
-----------------------------------------------------------------------------------
Key: HHH-7287
URL: https://hibernate.onjira.com/browse/HHH-7287
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.2
Environment: Database access with isolation level < SNAPSHOT
Reporter: Guenther Demetz
Problem was originally exposed by Madhumita Sadhukhan in a email to hibernate-dev(a)lists.jboss.org at Fri 4/27/2012 .
The bug (email point 6) get isolated by following matrix-test-case:
{code:title=org.hibernate.test.naturalid.mutable.MutableNaturalIdTest.java|borderStyle=solid}
@Test
public void testModificationInOtherSession() {
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User( "gavin", "hb", "secret" );
s.persist( u );
t.commit();
s.close();
s = openSession();
// Use transactionless session
assertNotNull( s.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "hb" ).load());
// CHANGE natural-id values in another session
Session other = openSession();
other.beginTransaction();
u = (User) other.byId( User.class ).getReference( u.getId() );
u.setOrg( "zz" );
other.getTransaction().commit();
other.close();
// CHANGE APPLIED
u = (User) s.byId( User.class ).getReference( u.getId() );
assertEquals(u, s.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "hb" ).load()); // found with cached old-values, OK
User u2 = (User) s.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "zz" ).load(); // the internal query will 'see' the new values, because isolation level < SERIALIZABLE
assertEquals(u, u2); // is it right here having u2 != null ? Yes, if we continue to see NaturalIdLoadAccess as a plain query. Maybe something to discuss
assertEquals("hb", u2.getOrg()); // entity itself must still contain the old value
assertNotNull( s.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "hb" ).load()); // this fails, that's the bug
s.close();
s = openSession();
s.beginTransaction();
s.delete( u );
s.getTransaction().commit();
s.close();
}
{code}
CAUSE:
The problem raises, when natural-id get resolved by query.
Here Hiberante uses the search-natural-id values for updating the cache, probably not being aware that in such situation they could differ from the natural-id-values in the current entity state. The cache-update then detects the old-values as obsolete and removes them, this explains why the second lookup with old values suddently returns null.
SOLUTION PROPOSAL:
After natural-id get resolved from query, first load the entity by identifier, and then cache the natural-id-values taking them from the entity state.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 2 months
[Hibernate-JIRA] Created: (HV-456) The MethodValidator could not handle Proxied objects like in EJB environment
by Ingo Bruell (JIRA)
The MethodValidator could not handle Proxied objects like in EJB environment
----------------------------------------------------------------------------
Key: HV-456
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-456
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.2.0.Beta2
Environment: linux, java 1.6.0_24, hibernate-validator-4.2.0.Beta2, JBoss-5.1.0.GA
Reporter: Ingo Bruell
Using the MethodValidator with proxied objects via an interceptor in an ejb environment throws the following exception:
javax.validation.ConstraintDeclarationException: Only the root method of an overridden method in an inheritance hierarchy may be annotated with parameter constraints. The following method itself has no parameter constraints but it is not defined on a sub-type of class de.enexoma.smartmeter.server.facade.config.ResourceBundleFacadeBean: MethodMetaData [method=public abstract java.util.Map de.enexoma.smartmeter.server.facade.ResourceBundleFacade.get(java.lang.String) throws de.enexoma.smartmeter.server.error.EnexomaException, parameterMetaData=[ParameterMetaData [type=class java.lang.String], [index=0], name=arg0], constraints=[], isCascading=false]], constraints=[], isCascading=false, hasParameterConstraints=false]
The method in the "real" class has constraints defined:
public Map<Locale,List<ResourceBundle>> get(@NotNull @Size(min=1)final String appName)
--
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
12 years, 2 months