hibernate

Problem saving Text file in database using Hibernate

I'm having a problem saving large text files to MySQL database. If the text file size is around 5KB it successfully saves. If file is 148KB then I get this error from Hibernate: org.hibernate.exception.DataException: Could not execute JDBC batch update These is the SQL shows by Hibernate: Hibernate: insert into file_table (ID,FILE) ...

Hibernate. 2 functions : simpleSave() , saveWithCascade() . can it be done ? and how ?

I have a scenario in which i have: A parent class Parent which has some simple properties (int, String, etc) and 2 set of children. Set childrenA; Set childrenB; Could i make a save function for parent simpleSave(Parent p) that will save/persists only the parent properties in the database and have a function saveWithCascade(Parent p) t...

Hibernate JPA Caching Problem

Ok, Here is my problem. I have a table named Master_Info_tbl. Its a lookup table: Here is the code for the table: @Entity @Table(name="MASTER_INFO_T") public class CodeValue implements java.io.Serializable { private static final long serialVersionUID = -3732397626260983394L; private Integer objectid; private String codetype; pr...

How do I establish table association in JPA / Hibernate with existing database?

Currently I have two tables in my database Encounters and Referrals: There is a one to many relationship between these two tables. Currently they are linked together with foreign keys. Right now I have public class Encounter extends JPASupport implements java.io.Serializable { @Column(name="referralid", unique=false, nulla...

"Local transaction already has 1 non-XA Resource: cannot add more resources" error

After reading previous questions about this error, it seems like all of them conclude that you need to enable XA on all of the data sources. But: What if I don't want a distributed transaction? What would I do if I want to start transactions on two different databases at the same time, but commit the transaction on one database and ro...

HQL to get elements that possess all items in a set

Currently, I have an HQL query that returns all Members who possess ANY Award from a set of specified Awards: from Member m left join m.awards as a where a.name in ("Trophy","Ribbon"); What I now need is HQL that will return all Members who possess ALL Awards specified in the set of Awards. So, assuming this data: Joe has Trophy, M...

2 one-to-many instead of 1 many-to-many

In Hibernate tutorial, chapter 25 best practices says we should use 2 one-to-many relationship instead of one many-to-many with an intermediate link class. I can't see what is the benefit of it : why is it better to create a 3d entity while the many-to-many can generate a join table that is acting as this intermediate link. However this...

Grails 1.3.1: Improved Query Caching

http://www.grails.org/1.3.1+Release+Notes Improved Query Caching The findAll query method now supports taking advantage of the 2nd level cache. Book.findAll("from Book as b where b.author=:author", [author:'Dan Brown'], [cache: true]) What advantages or disadvantages of using 2nd level cache ? I'm developing web-server ...

Compound Primary Key in Hibernate using Annotations

Hi, I have a table which uses two columns to represent its primary key, a transaction id and then the sequence number. I tried what was recommended http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping in section 2.2.3.2.2, but when I used the Hibernate session to commit this Entity object, it leav...

Hibernate can't load Custom SQL collection

Hi, There is a table Item like, code,name 01,parent1 02,parent2 0101,child11 0102,child12 0201,child21 0202,child22 Create a java object and hbm xml to map the table.The Item.parent is a Item whose code is equal to the first two characters of its code : class Item{ String code; String name; Item parent; List<Item> ch...

How can I disable Hibernate-cache logs?

Hi guys, My Grails app log is being flooded with thousands of messages like: 2010-05-21 18:54:08,261 [30462143@qtp-19943008-38] DEBUG hibernate.EhCache - key: ga_event value: 5220206380077056 This is my log4j config: // log4j configuration log4j = { // Example of changing the log pattern for the default console // appender: ...

out-of-the-box way to get an idmap from hibernate for a given entity?

Over and over again I notive myself getting a list from hibernate, and the first thing next is put it in an idmap like: List<House> entities = s.createCriteria(House.class).list(); Map<String,House> entitymap = new HashMap<String,House>(); for(TA_entity e:entities){ entitymap.put(e.getId(), e); } Is there a way to get this dire...

How to change Hibernate´s auto persistance strategy

I just noted that my hibernate entities are automatically persisted to the database (or at least to cache) before I call any save() or update() method. To me this is a pretty strange default behavior but ok, as long as I can disable it, it´s fine. The problem I have is I want to update my entity´s state (from 1 to 2) only if the entity ...

Hibernate criteria query to match against all child collection elements

Hi, This question is very similar to this one but the responses were minimal to that question. I have a parent class with a Set of child entities. The child entities are just a wrapper for a string and live in a different table to the parent entity. I want to have a criteria query that returns the parent entities when all the members o...

Criteria API - How to get records based on collection count?

Hello Guys! I have a Question class in ActiveRecord with following fields: [ActiveRecord("`Question`")] public class Question : ObcykaniDb<Question> { private long id; private IList<Question> relatedQuestions; [PrimaryKey("`Id`")] private long Id { get { return this.id; } set { this.id = value; } }...

JPA GeneratedValue with GenerationType.TABLE does a big jump after jvm restart

When I start my server and add an entry, the generated id will start with 1, 2, so on and so forth. After a restart, adding an entry would generate an id like 32,xxx. Another restart and adding of entry would generate an id like 65,xxx. I don't know why this is happening. Here's a snippet of the annotation I'm using for my id. I'm usin...

Hibernate/Lucene/HibernateSearch: find all words that start with specific prefix.

I want to get a list of all words in a database table that start with a specific prefix. I've been looking for a way to query the terms in a Lucene index (I need the terms, I don't care about the documents they are from) but without success. Any ideas? ...

Hibernate constraint ConstraintViolationException. Is there an easy way to ignore duplicate entries?

Basically I've got the below schema and I'm inserting records if they don't exists. However when it comes to inserting a duplicate it throws and error as I would expect. My question is whether there is an easy way to make Hibernate to just ignore inserts which would in effect insert duplicates? CREATE TABLE IF NOT EXISTS `method` ( `...

What's the reason behind the jumping GeneratedValue(strategy=GenerationType.TABLE) when not specifying a @TableGenerator?

Why do I need to add allocationSize=1 when using the @TableGenerator to ensure that the id wouldn't jump from 1, 2,... to 32,xxx, 65,xxx,... after a jvm restart? Is there a design reason for the need to specify the allocationSize? This snippet would produce the jumping ids @Id @GeneratedValue(strategy = GenerationType.TABLE) private L...

hibernate versioning parent entity

Consider two entities Parent and Child. Child is part of Parent's transient collection Child has a ManyToOne mapping to parent with FetchType.LAZY Both are displayed on the same form to a user. When user saves the data we first update Parent instance and then Child collection (both using merge). Now comes the tricky part. When user...