[Hibernate-JIRA] Created: (HHH-5759) ehcache causes deadlock
by senthil (JIRA)
ehcache causes deadlock
-----------------------
Key: HHH-5759
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5759
Project: Hibernate Core
Issue Type: Bug
Components: caching (L2)
Affects Versions: 3.5.2
Environment: ehcache 1.2.0, oracle 11g, weblogic 10 and hibernate 3.5.2
Reporter: senthil
Priority: Critical
We have following mapping in our model,
<class name="Employee" table="employee">
<cache usage="read-only" name="basic_cache" />
<id name="id" column="news_id">
<generator class="native"/>
</id>
<many-to-one name="person" class="Person" column="person_id" not-null="true" />
</class>
<class name="Person" table="Person">
<cache usage="read-only" name="basic_cache" />
<id name="id" column="person_id" />
<property name="firstName" column="person_firstName" />
<property name="secondName" column="person_secondName" />
<set name="PhoneNumbers" table="PHONE" cascade="none" order-by="phoneNumber asc">
<cache usage="read-only" name="basic_cache" />
<key column="phone_id" />
<one-to-many column="PHONE_ID" class="Phone" />
</set>
</class>
<class name="Phone" table="PHONE">
<cache usage="read-only" name="basic_cache" />
<composite-id>
<key-property name="number"/>
<key-many-to-one name="addressDetails" class="Address" >
<column name="addressId" />
</key-many-to-one>
</composite-id>
<property name="phoneType" type="string" length="10" column="PHONE_TYPE" />
<property name="phoneNumber" type="string" length="15" column="PHONE_NUMBER" />
</class>
<class name="Address" table="Address">
<cache usage="read-only" name="basic_cache" />
<id name="id" column="address_id"/>
<property name="street" />
<property name="houseNumber" />
</class>
The POJO object is normal as depends on the property in the model,
The below one is the basic listing of the classes, please bear for that if you find any syntax error,
public class Person {
Long id;
// here all the properties are declared with getter and setter but there is no equals and hashcode
}
public class Phone implements Serializable {
Long number;
Address addressDetails;
// the remaining properties are declared as normal
public boolean equals(Object obj) {
Phone newPhone = (Phone) obj;
return EqualsHelper.equals(this.number, newPhone.getNumber()) && EqualsHelper.equals(addressDetails, newPhone.getAddressDetails());
}
public int hashCode() {
int result = 31;
if(number == null) {
result = result * super.hashCode();
} else {
result = result * number.hashCode();
}
if(addressDetails!=null) {
result = result * addressDetails.hashCode();
}
return result;
}
}
public class Address implements Serializable {
Long id;
// the remaining properties declared as normal
public boolean equals(Object obj) {
Address address = (Address) obj;
return EqualsHelper.equals(this.id, address.getId());
}
public int hashCode() {
int result = 31;
if(id == null) {
result = result * super.hashCode();
} else {
result = result * id.hashCode();
}
return result;
}
}
public class BatchLoad {
public static void main(String args[]) {
for(;;) {
//fetch all persons in the person table and run that in a separate thread,
// I mean for eg. run 10000 persons into 12 threads
}
public class BatchRun implements Runnable {
public void run() {
for(int empNumberstartswith = 100; empNumberStartWith <= 800; empNumberstartswith++) {
Session session = SessionFactory.getCurrentSession();
Person p = (Person)session.get(Person.class, new Long(empNumberStartswith));
// rest of the operations by accessing p
}
}
}
}
}
Here, the problem is that loading and processing of Person works fine with 1 thread or sometimes even with 8 threads. But, when the number of threads are more than 8 then there is java level deadlock happens in loading Person and accessing Phone and subject.
The main point is that we don't have any synchronized block in our code. In ehcache the ReadWriteEntrantLock with Cache.put and ReadEntrantLock with Cache.get is causing the deadlock. It really made our life frustrating as this is now also happening in our online server as well, ie. with 15 or 20 users no issues if it crosses 20 then no more request accepted from Application server the ehcache makes every subsequent to deadlock state.
If its needed I can place the whole stack trace. Its mainly happening while writing into cache and reading into cache value though we only use read-only cache.
Any explanation would be very helpful or if you think our mapping is issue then please point it.
Thank you very much in advance!
Regards,
Senthil
--
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, 7 months
[Hibernate-JIRA] Created: (HHH-5758) A code bug in AbstractPersistor class ...
by Vince (JIRA)
A code bug in AbstractPersistor class ...
------------------------------------------
Key: HHH-5758
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5758
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0
Environment: All
Reporter: Vince
Here is code snippet:
protected int dehydrate(
Serializable id,
Object[] fields,
boolean[] includeProperty,
boolean[][] includeColumns,
int j,
PreparedStatement st,
SessionImplementor session) throws HibernateException, SQLException {
return dehydrate( id, fields, null, includeProperty, includeColumns, j, st, session, 1 );
}
The thing is .. it passes hardcoded '1' as the last argument .. which makes it impossible to write a custom generator for composite keys.
It assumes that "public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert()" function would never add any column of of composite key on its own. I think it is buggy and right now the only alternative i have is to parse the SQL string.
--
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, 7 months
[Hibernate-JIRA] Created: (HV-230) Database Connective or @Unique
by Ken Egervari (JIRA)
Database Connective or @Unique
------------------------------
Key: HV-230
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-230
Project: Hibernate Validator
Issue Type: New Feature
Affects Versions: 3.1.0.GA
Reporter: Ken Egervari
Priority: Critical
I find a common validation use case is checking to see if a field is unique to all those in the table, such as emails, isbns, usernames, keywords, etc. these fields may not be the primary key, but still need to be unique.
It would be fantastic if hibernate validator implemented this.
This is a common problem though because the domain class will need to have access the database. I dunno if there's an easy way to wire in a copy of sessionFactory to make this easy to write.
Perhaps something like this:
@Query( "select user from User user where user.emailAddress = :this.emailAddress and user.id != :this.id", message = "That Email is already being used by another user in the system" )
private String emailAddress;
Basically the idea is that if @Query returns no results, then the validation constraint is good, and if returns more than 1 result, then it fails. Kind of like simpleJdbcTemplate.queryForMap() does within the Spring testing framework. That method causes the test to fail if no row is returned, because it expects 1 result.
If it were possible to just say
@Unique
private String emailAddress;
That would be extremely concise and would save people a ton of time.
Of course, this requires some interoperability with Hibernate... but I think that's a good thing, no?
Thanks for taking this into consideration. I'd appreciate an email letting me know how to do this in a clean way in 3.1.0 GA as it is as well if you would. Thank you.
--
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, 7 months
[Hibernate-JIRA] Updated: (HHH-1283) ScrollableResults JoinFetch don't set child collection correctly after the second parent object
by Frans Flippo (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1283?page=c... ]
Frans Flippo updated HHH-1283:
------------------------------
Attachment: fetch-scroll-collection-3.5.4.patch
Patch in the root of the Hibernate dist with
patch -p1 <fetch-scroll-collection-3.5.4.patch
> ScrollableResults JoinFetch don't set child collection correctly after the second parent object
> -----------------------------------------------------------------------------------------------
>
> Key: HHH-1283
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1283
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1
> Environment: Hibernate 3.1
> Oracle10gR2
> Oracle JDBC Driver 10.2.0.1.0
> Sun JDK 1.5.0_06
> Spring 1.2.6
> Reporter: Masahiro Hirashima
> Attachments: fetch-scroll-collection-3.5.4.patch, ScrollableCollectionFetchingTest.java, ScrollableResults.zip
>
>
> ScrollableResults JoinFetch set child collection correctly at first parent object.
> but after the second parent object, It set only the first element of a child collection.
> I made the following tables.
> CREATE TABLE owners (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> first_name VARCHAR(30),
> last_name VARCHAR(30),
> address VARCHAR(255),
> city VARCHAR(80),
> telephone VARCHAR(20),
> version NUMBER(36, 0) DEFAULT 0
> );
> CREATE TABLE types (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> name VARCHAR(80),
> version NUMBER(36, 0) DEFAULT 0
> );
> CREATE TABLE pets (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> name VARCHAR(30),
> birth_date DATE,
> type_id NUMBER(36, 0),
> owner_id NUMBER(36, 0),
> version NUMBER(36, 0) DEFAULT 0
> );
> and inserted the following data.
> INSERT INTO owners VALUES (1, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749', 0);
> INSERT INTO owners VALUES (2, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763', 0);
> INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1, 0);
> INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 2, 1, 0);
> INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 3, 2, 0);
> INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 4, 2, 0);
> INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 5, 2, 0);
> INSERT INTO types VALUES (1, 'cat', 0);
> INSERT INTO types VALUES (2, 'dog', 0);
> INSERT INTO types VALUES (3, 'lizard', 0);
> INSERT INTO types VALUES (4, 'snake', 0);
> INSERT INTO types VALUES (5, 'bird', 0);
> and I execute following code.
> String hqlJoinFetchTest =
> "from Owner owner " +
> "left outer join fetch owner.pets as pets " +
> "left outer join fetch pets.type " +
> "order by owner.firstName, owner.lastName";
> Query query = session.createQuery(hqlJoinFetchTest);
> ScrollableResults cursor = query.scroll();
> while ( cursor.next() ) {
> Owner owner = (Owner)cursor.get(0);
> System.out.println(owner);
> }
> result of this code is following.
> petclinic.domain.Owner@15d616e[id=1,version=0,firstName=Betty,lastName=Davis,
> petclinic.domain.Pet@136d9d8[id=2,version=0,name=Basil,birthDate=2002-08-06,
> petclinic.domain.PetType@1be2893[id=2,version=0,name=dog]
> petclinic.domain.Pet@14a75bb[id=1,version=0,name=Leo,birthDate=2000-09-07,
> petclinic.domain.PetType@17779e3[id=1,version=0,name=cat]
> petclinic.domain.Owner@e3570c[id=2,version=0,firstName=Eduardo,lastName=Rodriquez
> petclinic.domain.Pet@167e3a5[id=4,version=0,name=Jewel,birthDate=2000-03-07,
> petclinic.domain.PetType@1926e90[id=4,version=0,name=snake]
> First owner object set collection collectly.
> but second owner object don't set second pet object(id=5) and third pet object(id=6).
--
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, 7 months
[Hibernate-JIRA] Commented: (HHH-1283) ScrollableResults JoinFetch don't set child collection correctly after the second parent object
by Frans Flippo (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1283?page=c... ]
Frans Flippo commented on HHH-1283:
-----------------------------------
I still get this issue with 3.5.4-Final. I've taken the patch attached to HHH-1751, adjusted it to work with the 3.5.4 source code, and applied it. This fixed the issue, as demonstrated also by the unit tests attached to HHH-1751 as well.
I'm attaching the modified patch files (which also include the test .java files and resources). I really hope someone from the Hibernate team can check them and include this in the trunk!
> ScrollableResults JoinFetch don't set child collection correctly after the second parent object
> -----------------------------------------------------------------------------------------------
>
> Key: HHH-1283
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1283
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1
> Environment: Hibernate 3.1
> Oracle10gR2
> Oracle JDBC Driver 10.2.0.1.0
> Sun JDK 1.5.0_06
> Spring 1.2.6
> Reporter: Masahiro Hirashima
> Attachments: fetch-scroll-collection-3.5.4.patch, ScrollableCollectionFetchingTest.java, ScrollableResults.zip
>
>
> ScrollableResults JoinFetch set child collection correctly at first parent object.
> but after the second parent object, It set only the first element of a child collection.
> I made the following tables.
> CREATE TABLE owners (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> first_name VARCHAR(30),
> last_name VARCHAR(30),
> address VARCHAR(255),
> city VARCHAR(80),
> telephone VARCHAR(20),
> version NUMBER(36, 0) DEFAULT 0
> );
> CREATE TABLE types (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> name VARCHAR(80),
> version NUMBER(36, 0) DEFAULT 0
> );
> CREATE TABLE pets (
> id NUMBER(36, 0) NOT NULL PRIMARY KEY,
> name VARCHAR(30),
> birth_date DATE,
> type_id NUMBER(36, 0),
> owner_id NUMBER(36, 0),
> version NUMBER(36, 0) DEFAULT 0
> );
> and inserted the following data.
> INSERT INTO owners VALUES (1, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749', 0);
> INSERT INTO owners VALUES (2, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763', 0);
> INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1, 0);
> INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 2, 1, 0);
> INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 3, 2, 0);
> INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 4, 2, 0);
> INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 5, 2, 0);
> INSERT INTO types VALUES (1, 'cat', 0);
> INSERT INTO types VALUES (2, 'dog', 0);
> INSERT INTO types VALUES (3, 'lizard', 0);
> INSERT INTO types VALUES (4, 'snake', 0);
> INSERT INTO types VALUES (5, 'bird', 0);
> and I execute following code.
> String hqlJoinFetchTest =
> "from Owner owner " +
> "left outer join fetch owner.pets as pets " +
> "left outer join fetch pets.type " +
> "order by owner.firstName, owner.lastName";
> Query query = session.createQuery(hqlJoinFetchTest);
> ScrollableResults cursor = query.scroll();
> while ( cursor.next() ) {
> Owner owner = (Owner)cursor.get(0);
> System.out.println(owner);
> }
> result of this code is following.
> petclinic.domain.Owner@15d616e[id=1,version=0,firstName=Betty,lastName=Davis,
> petclinic.domain.Pet@136d9d8[id=2,version=0,name=Basil,birthDate=2002-08-06,
> petclinic.domain.PetType@1be2893[id=2,version=0,name=dog]
> petclinic.domain.Pet@14a75bb[id=1,version=0,name=Leo,birthDate=2000-09-07,
> petclinic.domain.PetType@17779e3[id=1,version=0,name=cat]
> petclinic.domain.Owner@e3570c[id=2,version=0,firstName=Eduardo,lastName=Rodriquez
> petclinic.domain.Pet@167e3a5[id=4,version=0,name=Jewel,birthDate=2000-03-07,
> petclinic.domain.PetType@1926e90[id=4,version=0,name=snake]
> First owner object set collection collectly.
> but second owner object don't set second pet object(id=5) and third pet object(id=6).
--
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, 7 months