[Hibernate-JIRA] Created: (HHH-6221) Hibernate throws AnnotationException on column used by multiple overlapping foreign keys
by Karsten Wutzke (JIRA)
Hibernate throws AnnotationException on column used by multiple overlapping foreign keys
----------------------------------------------------------------------------------------
Key: HHH-6221
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6221
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, entity-manager
Affects Versions: 3.6.0
Environment: Hibernate 3.6.0, HSQLDB 2, JavaSE (probably all Hibernate versions to date affected)
Reporter: Karsten Wutzke
Priority: Critical
Attachments: overlapping-fks-hib-broken.zip
Here's a view of the design:
!http://www.kawoolutions.com/media/postareas-min.png!
Simple logic: two tables use composite PKs and use a country_code column in the PK. PostAreas is a simple join table so its PK is comprised of the two linked tables' PK columns. Problem: both FKs in PostAreas use country_code to produce an overlap.
This is per se nothing special, but in the context of JPA it is: there may be only one writable mapping in the @JoinColumn annotations, all other must be set to read-only, that is _insertable = false, updatable = false_.
Here are the (incomplete) mappings (full SSCCE attached):
{code:java}
@Entity
@Table(name = "Zips")
@IdClass(value = ZipId.class)
public class Zip implements Serializable
{
@Id
@Column(name = "country_code")
private String countryCode;
@Id
@Column(name = "code")
private String code;
...
}
{code}
{code:java}
public class ZipId implements Serializable
{
private String countryCode;
private String code;
...
}
{code}
{code:java}
@Entity
@Table(name = "Cities")
@IdClass(value = CityId.class)
public class City implements Serializable
{
@Id
@Column(name = "country_code")
private String countryCode;
@Id
@Column(name = "state_code")
private String stateCode;
@Id
@Column(name = "name")
private String name;
...
}
{code}
{code:java}
public class CityId implements Serializable
{
private String countryCode;
private String stateCode;
private String name;
...
}
{code}
{code:java}
@Entity
@Table(name = "PostAreas")
@IdClass(value = PostAreaId.class)
public class PostArea implements Serializable
{
@Id
@Column(name = "country_code", insertable = false, updatable = false)
private String countryCode;
@Id
@Column(name = "state_code", insertable = false, updatable = false)
private String stateCode;
@Id
@Column(name = "zip_code", insertable = false, updatable = false)
private String zipCode;
@Id
@Column(name = "city_name", insertable = false, updatable = false)
private String cityName;
@ManyToOne
@JoinColumns(value = {
@JoinColumn(name = "country_code", referencedColumnName = "country_code"),
@JoinColumn(name = "zip_code", referencedColumnName = "code")
})
private Zip zip;
@ManyToOne
@JoinColumns(value = {
@JoinColumn(name = "country_code", referencedColumnName = "country_code", insertable = false, updatable = false), // <- !!!
@JoinColumn(name = "state_code", referencedColumnName = "state_code"),
@JoinColumn(name = "city_name", referencedColumnName = "name")
})
private City city;
...
}
{code}
{code:java}
public class PostAreaId implements Serializable
{
private String countryCode;
private String stateCode;
private String zipCode;
private String cityName;
...
}
{code}
Looking at PostArea.city (*scroll down in the PostArea code box!*): the @JoinColumn for country_code is set to read-only on City and to writable on Zip. However, when running this from a JavaSE test app Hibernate fails with an AnnotationException:
{code}
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: postareas] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.postareas.Main.main(Main.java:38)
Caused by: org.hibernate.AnnotationException: Mixing insertable and non insertable columns in a property is not allowed: tld.postareas.model.PostAreacity
at org.hibernate.cfg.Ejb3Column.checkPropertyConsistency(Ejb3Column.java:563)
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2703)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1600)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3977)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3931)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
... 4 more
{code}
When mapping a table that uses the same column in two or more foreign keys, only one of the relationships' @JoinColumn annotations may be tagged as writable. However, mixing read-only and writable in a multi-column relationship *must* be supported.
--
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, 1 month
[Hibernate-JIRA] Created: (HHH-6349) AuditJoinTable rows missing when detached entities with collections are merged into the persistence context
by Erik-Berndt Scheper (JIRA)
AuditJoinTable rows missing when detached entities with collections are merged into the persistence context
-----------------------------------------------------------------------------------------------------------
Key: HHH-6349
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6349
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 4.0.0.Beta1, 3.6.5
Reporter: Erik-Berndt Scheper
Assignee: Erik-Berndt Scheper
Given an Entity that is audited by Envers, which contains more than one collection (e.g. two Lists); for example
{code:title=MultipleCollectionEntity .java|borderStyle=solid}
Entity
@org.hibernate.envers.Audited
public class MultipleCollectionEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", length = 10)
private Long id;
@Version
@Column(name = "VERSION", nullable = false)
private Integer version;
@Column(name = "TEXT", length = 50, nullable = false)
private String text;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MCE_ID", nullable = false)
@org.hibernate.envers.AuditJoinTable(name = "MCE_RE1_AUD", inverseJoinColumns = @JoinColumn(name = "RE1_ID"))
private List<MultipleCollectionRefEntity1> refEntities1 = new ArrayList<MultipleCollectionRefEntity1>();
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MCE_ID", nullable = false)
@org.hibernate.envers.AuditJoinTable(name = "MCE_RE2_AUD", inverseJoinColumns = @JoinColumn(name = "RE2_ID"))
private List<MultipleCollectionRefEntity2> refEntities2 = new ArrayList<MultipleCollectionRefEntity2>();
{code}
Envers stores the audit information for additions and deletions to these Lists in AuditJoinTables (MCE_RE1_AUD and MCE_RE2_AUD). This process is driven by the Hibernate collection events; to be exact by the difference between the current contents of the collection (using event.getCollection()) and the contents of the stored snapshot of this collection (using collectionEntry.getSnapshot()).
This works fine as long as the given entity is available in the current persistence context.
Unfortunately, this is not the case when detached entities are merged back into the persistence context.
In this case, the end result is that audit information is stored in the MultipleCollectionEntity_AUD table, in the MultipleCollectionRefEntity1_AUD table and the MultipleCollectionRefEntity2_AUD table. However, the AuditJoinTable rows are missing.
Effectively this means that the rows in MultipleCollectionRefEntity2_AUD are dangling and that the audit information when refEntities were added or deleted to the refEntities1 and refEntities2 collections has been irretrievably lost.
I have prepared Envers test cases for the 3.6.x and 4.0.x versions and will be adding them shortly.
--
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, 1 month
[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: (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