[Hibernate-JIRA] Created: (HHH-6037) doesn't remove the orphan entry
by Premraj Motling (JIRA)
doesn't remove the orphan entry
-------------------------------
Key: HHH-6037
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6037
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.3
Environment: Hibernate 3.5.3, JPA 2, ORACLE 11g
Reporter: Premraj Motling
Hibernate don't delete the orphan entries with OneToOne even after set to null
@Entity
public class Foo{
@Id
private long foo_id;
private String name;
@OneToOne(mappedBy = "foo", orphanRemoval = true)
private FooProperties fooProperties;
}
@Entity
public class FooProperties{
@Id
private long fp_id;
private String phoneNumber;
@OneToOne
@JoinColumn(name = "foo_id", nullable = false)
private Foo foo;
}
and if I do -
Foo foo = entityManager.find(Foo.class, fooId);
foo.getFooProperties.setFoo(null);
foo.setFooProperties(new FooProperties("xxx-xxx-xxx"));
entityManager.merge(foo);
its not deleting the FooProperties
--
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-4910) L2 parent collection cache eviction when a child is added/updated/removed
by Julien Kronegg (JIRA)
L2 parent collection cache eviction when a child is added/updated/removed
-------------------------------------------------------------------------
Key: HHH-4910
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4910
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1, DB2 390
Reporter: Julien Kronegg
Priority: Minor
Hibernate should automatically evict the collection cache an entity is persisted/updated/removed.
Some precisions:
- I'm not wanting to update the collection cache, evicting is fine
- Doing persisted/updated/removed operation by using the collection add/remove evicts the collection
- Doing persisted/updated/removed operation on the child entity does not evict the collection
h3. Test case
I have test case with a Parent entity which holds a OneToMany Set<Child> called 'children':
{code}
...
@Entity
@Table(...)
public class Parent {
@Id
private long id;
@OneToMany(mappedBy="parent", fetch=FetchType.LAZY)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Child> children;
... getters and setters
}
@Entity
@Table(...)
public class Child {
@Id
private long id;
@ManyToOne()
private Parent parent;
... getters and setters
}
{code}
Level 2 cache is configured as follow:
- EhCache 1.6.2, default configuration, L2 cache activated
- entities are not cached
- the 'children' collection is cached
- no queries are cached
The L2 cache works as expected when reading the Parent's children collection size:
1. new EntityManager
2. loading myParent -> makes a SQL query on the Parent table
3. calling myParent.getChildren().size() -> makes a SQL query on the Child table
4. new EntityManager
5. loading myParent -> makes a SQL query on the Parent table (since entities are not cached)
6. calling myParent.getChildren().size() -> hit the L2 cache (no SQL queries)
The test case consists in
- persisting a new Child with a Parent
- updating a Child's Parent (i.e. changing its Parent for another Parent)
- deleting a Child with a Parent
When doing the test case by managing the Parent.children collection (e.g. myParent.getChildren().add(myNewChild)), the L2 cache works as expected:
the Parent.children collection is evicted from the L2 cache and the next myParent.getChildren().size() makes a SQL query.
But when doing the test case by managing the Child.parent, the L2 cache does not work as expected: the Parent.children collection is not evicted from L2 cache.
Example 1: persist
{code}
Parent myParent = em.find(Parent.class, 1);
System.out.println(em.find(Parent.class, 1).getChildren().size()); // by now, the Parent has 0 children
Child myChild = new Child();
myChild.setParent(myParent);
em.persist(myChild);
em.flush();
em = ... // get a new EntityManager
System.out.println(em.find(Parent.class, 1).getChildren().size()); // still 0 children
{code}
--> myParent.children has still the previous size (i.e. 0 instead of 1)
Example 2: update
{code}
Child myChild = em.find(Child.class, 1);
Parent myParent = em.find(Parent.class, 1);
em.refresh(myParent); // refresh to be sure to bypass the L2 collection cache
System.out.println(em.find(Parent.class, 1).getChildren().size()); // by now, the Parent has 1 children
myChild.setParent(null);
em.flush();
em = ... // get a new EntityManager
System.out.println(em.find(Parent.class, 1).getChildren().size()); // still 1 children
{code}
-> myParent.children has still the previous size (i.e. 1 instead of 0)
Example 3: remove
{code}
Child myChild = em.find(Child.class, 1);
Parent myParent = em.find(Parent.class, 1);
em.refresh(myParent); // refresh to be sure to bypass the L2 collection cache
System.out.println(em.find(Parent.class, 1).getChildren().size()); // by now, the Parent has 1 children
em.remove(myChild);
em.flush();
em = ... // get a new EntityManager
System.out.println(em.find(Parent.class, 1).getChildren().size()); // still 1 children and raise EntityNotFoundException
{code}
-> myParent.children has still the previous size and a EntityNotFoundException is raised because the deleted cached element cannot be found in the database
This problem is also reported here:
- http://stackoverflow.com/questions/1505940/hibernate-ehcache-evicting-col...
- http://stackoverflow.com/questions/1470502/hibernate-clean-collections-2n...
And is more or less related to the following JIRA issues:
- http://opensource.atlassian.com/projects/hibernate/browse/HHH-496
- http://opensource.atlassian.com/projects/hibernate/browse/HHH-1444
- http://opensource.atlassian.com/projects/hibernate/browse/HHH-1913
h3. Expected behavior
For these test cases, I expected the L2 cache behavior to be as follow:
1. when a new Child is persisted/removed, the collection which own it is evicted from the collection cache
This means:
{code}
mySessionFactory.evictCollection("Parent.children", myChild.getParent().getId());
{code}
2. when a Child parent changes, the collection which was owning the child AND the collection which own the child are evicted from the collection cache
This means:
{code}
mySessionFactory.evictCollection("Parent.children", myChildBeforeChange.getParent().getId());
mySessionFactory.evictCollection("Parent.children", myChild.getParent().getId());
{code}
This behavior would probably be implemented in the following classes:
- org.hibernate.action.EntityInsertAction
- org.hibernate.action.EntityDeleteAction
- org.hibernate.action.EntityUpdateAction
See http://opensource.atlassian.com/projects/hibernate/browse/HHH-1913 for a patch temptative (incomplete: some code is missing)
h3. Workaround:
When working with JPA/Hibernate annotations, the above behavior can be implemented using reflection as such (pseudo-code):
1. listen to persist/update/remove entity events: @EntityListeners, @PostPersist, @PostRemove, @PreUpdate
2. in the @PostPersist/@PostRemove entity event listener:
a. get all @ManyToOne fields/properties of the entity class (i.e. 'children' property of Child) and get the mapped class (i.e. Parent)
b. get the collectionName (i.e. field name of Parent class with @OneToMany annotation and a type of Collection<Child>)
c. build the collectionRole as Parent.class.getName()+"."+collectionName
d. get the entityKey as the identifier of the field found in (a)
e. call mySessionFactory.evictCollection(collectionRole, entityKey)
3. in the @PreUpdate entity event listener:
a. get all @ManyToOne fields/properties of the entity class (i.e. 'children' property of Child) and get the mapped class (i.e. Parent)
b. get the collectionName (i.e. field name of Parent class with @OneToMany annotation and a type of Collection<Child>)
c. build the collectionRole as Parent.class.getName()+"."+collectionName
d. get the entityKey as the identifier of the field found in (a) for the current entity
e. get the previousEntityKey as the identifier of the field found in (a) for the previous entity
f. if entityKey!=previousEntityKey then
call mySessionFactory.evictCollection(collectionRole, entityKey)
call mySessionFactory.evictCollection(collectionRole, previousEntityKey)
We tested this workaround with success. The event listener lasts for about 3 us/call (microseconds) which is okay.
Advantages:
- easy for the programmer (no need for entityManager.refresh(myParent) or mySessionFactory.evictCollections())
- clean code
Disadvantages:
- @EntityListeners annotation to be put on every entity
- requires Hibernate configuration by annotations on entities (does not work with XML configuration)
--
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-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-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
[Hibernate-JIRA] Created: (HSEARCH-741) NPE using two fulltext filters, one of them matching nothing (some filters only)
by Sanne Grinovero (JIRA)
NPE using two fulltext filters, one of them matching nothing (some filters only)
--------------------------------------------------------------------------------
Key: HSEARCH-741
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-741
Project: Hibernate Search
Issue Type: Bug
Affects Versions: 3.4.0.Final, 3.3.0.Final, 3.2.1, 3.2.0.Final, 3.1.1.GA, 3.1.0.GA
Reporter: Sanne Grinovero
Assignee: Sanne Grinovero
Fix For: 3.5
It seems that some filter implementations are allowed to return null instead of an empty iterator if they don't match any document.
In this case if multiple filters are enabled, and they are eligible for bitset merging, and no matches where found, we get:
{code}java.lang.NullPointerException
org.hibernate.search.filter.AndDocIdSet.findFirstTargetPosition(AndDocIdSet.java:144)
org.hibernate.search.filter.AndDocIdSet.makeDocIdSetOnAgreedBits(AndDocIdSet.java:89)
org.hibernate.search.filter.AndDocIdSet.buildBitSet(AndDocIdSet.java:81)
org.hibernate.search.filter.AndDocIdSet.iterator(AndDocIdSet.java:60)
org.apache.lucene.search.IndexSearcher.searchWithFilter(IndexSearcher.java:550)
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:525)
org.hibernate.search.query.engine.impl.QueryHits.updateTopDocs(QueryHits.java:219)
org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:127)
org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:419)
org.hibernate.search.query.engine.impl.HSQueryImpl.queryEntityInfos(HSQueryImpl.java:222)
org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:206)
com.example.dao.impl.DaoImpl.search(Unknown Source)
....{code}
--
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-3706) Audit Table Schema not generated using <annotationconfiguration>
by Kaizer (JIRA)
Audit Table Schema not generated using <annotationconfiguration>
----------------------------------------------------------------
Key: HHH-3706
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3706
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.3.1
Reporter: Kaizer
The Ant task to generate the schema for the audit tables generates schema for my entities but none of the Audit tables are. I have used the org.hibernate.tool.ant.EnversHibernateToolTask class.
<target name="schemaexport" depends="compile" description="Exports a generated schema to DB and file">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask" classpathref="hibernate" />
<hibernatetool destdir=".">
<classpath>
<path refid="hibernate"/>
</classpath>
<!--<annotationconfiguration configurationfile="${basedir}/src/config/hibernate.cfg.xml"/>-->
<jpaconfiguration persistenceunit="ConsolePU"/>
<hbm2ddl drop="false" create="true" export="false" outputfilename="versioning-ddl.sql" delimiter=";" format="true" />
</hibernatetool>
</target>
It works on using <jpaconfiguration>.
--
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