hibernate

How to reuse existing connection in Open Session In view pattern implementation of Hibernate?

I am using Hibernate by implementing "Open Session in view" pattern?It opens a new connection per request. Is there any way to use the existing connection? Is my understanding correct? May be i miss something during implementation which cause opening of new connection? ...

UTF8 - Hibernate/MySQL weirdness

I have a db in production where all of my tables are using utf8 / utf8_general_ci encoding. This is basically working fine except in one scenario. What happens is that ??? are being returned for some characters (Chinese, etc); however, they are also returned correctly for the same table but via a different criteria. I've double checked...

Hibernate Query vs Criteria Performance

I recently had a rather strange phenomenon. Had to obtain a count that included joins over multiple tables with different WHERE conditions. I implemented the query first with the criteria API of hibernate. It correctly created the requested prepared SQL statement but was rather slow. Re-implemented then the entire query using HQL. Was ra...

PreUpdate not firing when adding to a collection

I have a JPA annotated class which contains a collection like so: @Entity public class Employee { @Id private int id; @Basic private String name; @OneToMany @JoinTable(name = "ORG", joinColumns = @JoinColumn(name="MINION"), inverseJoinColumns = @JoinColumn(name="EMP")) private List<Employee> minions = ...

Hibernate query a foreign key field with ID

For example, I have two entities: Employee and Address. Of these enitities, Employee has a foreign key AddressID references the ID column on Address. In the Java domain objects, Hibernate nicely wraps the forgein key integer field with a Address object field. But now, how could I query the Employee with a certain AddressID? I have trie...

Hibernate - apply locks to parent tables in polymorphic queries

I have two objects: public class ParentObject { // some basic bean info } public class ChildObject extends ParentObject { // more bean info } Each of these tables corresponds to a differnet table in a database. I am using Hibernate to query the ChildObject, which will in turn populate the parent objects values. I have defined my m...

Getting list in order, mapped by join table

I have two entities that have a many-to-many relationship; they are mapped with annotations @ManyToMany and @JoinTable. In the database join table I also have "order" column which would indicate in which order B entities are listed in A. (The ordering of Bs is specific for each A). How can I get Hibernate to order list according to the ...

Manual Transactions with Seam POJO

What is best practice for using Database Transactions with Seam when not using EJBs - ie. when deploying Seam as a WAR? By default Seam JavaBeans support Transactions. I can annotate a method with @Transactional and that will ensure that a transaction is required. Or I can use @Transactional(NEVER) or @Transactional(MANDATORY). What I c...

Hibernate queries slow down drastically after an entity is loaded in the session

I'm using Hibernate EntityManager, and am experiencing a weird slowdown in my Hibernate queries. Take a look at this code: public void testQuerySpeed() { for(int i = 0; i < 1000; i++) { em.createNativeQuery("SELECT 1").getResultList(); } } This runs in about 750ms on my machine. Not blazing fast considering it's just s...

Hibernate problem

Hi, I have a problem with some queries which get duplicated at the database automatically after 80 seconds. This colapses the database because each thread duplicates after 80 seconds if it has not received any information. I really don't know what to do... This is the pool I have defined: <property name="c3p0.acquire_increment">1...

JPA(hibernate) @Id Error:Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'DbName.system_sequences' doesn't exist

Below is my entity id's definition and I am using hibernate as the jpa implemention @Id @TableGenerator(name="customer_generator", table="system_sequences",pkColumnName="sequence_name", valueColumnName="sequence_next_hi_value",initialValue=1,allocationSize=20) @GeneratedValue(strategy = GenerationType.TABLE, generator = "customer_ge...

Querying entities which have a specific collection entry using HQL

I have Item objects which have a collection of attributes defined as a map. Now I want to retrieve all objects which have a specific attribute (by name, locale and value) An expecert of the Item mapping: <map table="ITEM_ATTRIBUTES" name="attributes"> <key column="item_id" foreign-key="fk_itmr_attrbts_itmrs"/> <composite-index clas...

making a jpa oneToMany relationship effective?

I have written a very basic and naive oneToMany relationship between a ChatComponent and its Chat Messages like this: @OneToMany List<ChatMessage> chatMessages; This basically works, i.e., doing something like: ChatMessage chatMessage = vo.toDomainObject(); chatMessage.setDate(new Date()); //Add the message to the chat component em.g...

Hibernate saveOrUpdate fails when I execute it on empty table.

I'm try to insert or update db record with following code: Category category = new Category(); category.setName('catName'); category.setId(1L); categoryDao.saveOrUpdate(category); When there is a category with id=1 already in database everything works. But if there is no record with id=1 I got following exception: org.hibernate.St...

Hibernate Mapping Conditional Many-To-One

I have to map a lecagy database for read-only purposes that contains the following structure: Table MAIN: id productId productType Table PRODUCT_A: id description_a Table PRODUCT_B: id description_b Table PRODUCT_C: id description_c Depending on the value in column productTyp, the productId refers either to the PRODUCT_A,PRODUC...

Annotations of Annotations in Java 5/6

I am setting up Hibernate Caching and want to cache certain entities in different regions. For example, some entities can be "stale" for up to 5 minutes, some for an hour, and some (like lookups) won't change for weeks. To facilitate easy config of regions in my code, I'm trying the following: I created an annotation named @LookupCache ...

NHibernate Polymorphic Query on a Collection

I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<...

Getting Jersey and Hibernate to work together?

I've got a project which requires both Jersey and Hibernate. Problem is they both use incompatible versions of a Jar file (asm.jar) under the covers. I've looked around Google and it appears that it's possible to get Hibernate to use another facility called Javassist, but when I try to follow the instructions it falls flat. I still get ...

How to split a table's data into two sets based on a column value with Hibnernate mappings?

Suppose there are three tables: Table A (ID, NAME) Table B (ID, NAME) Table A-B (A_ID, B_ID, Boolean_Property) and Table A and B are modeled by classes A and B as follows: public class A { private long id; private String name; // All the B's that belong to A where the boolean property is True Set<B> trueBSet; //...

Hibernate with Oracle 11g not working with "select" generator

Hello there. I am using Hibernate 3.2.5 and Hibernate Annotations 3.3.1.GA as the JPA provider in a data loading application. I have configured Hibernate to use C3P0 for connection pooling. My database is: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production As there is no built in hibernate dialect for 11g, ...