hibernate

Generate value for a property in hibernate

I want to generate a unique guid/uuid value for a property which is not a primary key in hibernate. In other words, I want to generate values for an alternate primary key. How can I do this using Hibernate? ...

Mapping a Natural Key with Hibernate Annotations

Hi, I have a legacy table that uses a column that holds a date as the natural prmary key to the table. I am trying to map this with hibernate, but for the life of me I can't figure out how to get hibernate to map a single (none-compound) natural key as the Id. I have it mapped like this: @Id @Temporal(TemporalType.TIMESTAMP) @Column(...

How to detect transaction conflicts with Hibernate?

I am using Hibernate 2.6 with hibernate-entitymanager. I am trying to catch and handle situations when 2 transactions conflict on an object. Here is what happens: Two threads are updating a single object wich has a @Version field. The thread which looses commit race logs StaleObjectStateException on flush. The exception is not thrown, i...

Null vs empty collections in Hibernate

Say I have the following Hibernate-mapped class: public class ClassA { @OneToMany(fetch=EAGER) private List<ClassB> bList; } When I read an object of ClassA from a Hibernate session, the bList field is initialized with a PersistentList object, as expected. I find myself with a requirement where in situations where the li...

Hibernate lazy initialization help

Hi, I have an issue trying to delete using hibernate. When I try to delete I get an exception saying that children exist and there is a FK violation. I want to delete the children also but the delete doesn't seem to be cascading. After about a week of trying to fix this issue I read that I should be using HibernateInterceptor to keep...

hibernate ignores fetch="join" on a collection when navigating the object tree with iterator

i have a forum with 1..n members each having 1..n articles, so this is my mapping: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; <hibernate-mapping auto-import="true"> <class name="Forum" table=...

Hibernate Self Join

Background I have a table with columns id, imageId, propertyId. There could be many images associated with a single property and there could be many properties associated with a single image. imageId - many-to-many - propertyId I have a list of propertyIds and I want to find out all the images associated with all the propertyIds usi...

How to add a Hibernate property that's really a query

We're using Hibernate to load objects that meet certain criteria. If the user decides to view the details on one of the objects, I want to pull up some additional information about the object. One of the "attributes" I'd like to show will require a fairly complex SQL query, but evaluates to a simple boolean. What's the right way to do...

Changing target table for Hibernate mapping

Is it possible to change the target table for a Hibernate mapping? My use case is that while I get the data from one table, in cases where the data cannot be processed it is stored in a error table for later analysis. Although it is possible to define entity-names in hibernate mappings, in my opinion it is not appropriate because it re...

Flex Hibernate - Setting up EntityManager and SessionFactory with Flex/Mate/ and BlazeDS

I am creating a Flex project using Mate, Blaze DS, Tomcat server. All of that seems to be working. Even my Hibernate calls are working. However they do not seem to be created in the correct way. I am logging in the user with the following block of code in java: public AbstractUser login(String username, String password){ //Configurati...

Hibernate: Create Mysql InnoDB tables instead of MyISAM

How can I get Hibernate (using JPA) to create MySQL InnoDB tables (instead of MyISAM)? I have found solutions that will work when using Hibernate to generate an SQL file to create the tables, but nothing that works "on the fly". ...

How do I make my pojos transactional?

I have a multi-threaded, multi-server web application with hibernate and spring managing transactions with AOP. The problem is, I need to maintain in-memory data and keep it current with the state of the database...essentially I'm implementing an in-memory cache. Now, is there any way to make my in-memory pojos transactional on the same...

How do I turn this HQL into a filter query?

I have this query: sess.createQuery("from Box b join b.items bi order by bi.name").list() It works fine. However, I have a hibernate's Collection boxes and want to filter is. Naive tries: sess.createFilter(boxes, "join this.items bi order by bi.name").list() sess.createFilter(boxes, "from this join this.items bi order by bi.name")....

Hibernate: How to eagerly fetch un-associated entities?

Java Persistence with Hibernate shows lots of examples of how to eagerly fetch associated entities, such as: Adding @org.hibernate.annotations.BatchSize to the associated class Adding @org.hibernate.annotations.Fetch to the field that references the associated class Using the "fetch" keyword in the HQL query, etc... However in my cas...

No Data insertion in user_info table.

Hi, i am trying to run one jbossESB program to test the data persistence. i have ClassInfo as POJO and corresponding table as user_info but i get this error once i do "ant sendesb"(this is hibernate specific). 13:59:51,225 ERROR [STDERR] org.hibernate.MappingException: Unknown entity: org. jboss.soa.esb.samples.quickstart.helloworl...

Hibernate: Clean collection's 2nd level cache while cascade delete items

I have a problem Hibernate does not update 2nd level cache for a collection of items which are subject of cascade removal. Details Assume we have an object Parent which has Parent.myChildren collection of Child objects. Now we have also object Humans with Humans.myAllHumans collection and all Parent and Child objects are in that collec...

NHibernate using single configuration file to connect to multiple dbs

I'd like to have a single configuration file and then when I'm creating a session change the hibernate-configuration->session-factory->connection.connection_string property to what I want it to be programmatically? Is it possible? UPDATE: I believe I may be able to do this like this Configuration cfg = new Configuration(); cfg.Configu...

Hibernate query by example (from Spring 3)

I've made my entity classes Adress, Road and County. A Road is in a County and an Adress in on a Road. I would like to list all the Adresses in a County. Therefore, in my AdressService I say: public List<Adress> AllAdresses(County county) { Adress adress = new Adress(); Road road = new Road(); road.setCounty(county); adress.setR...

Retrieve emebedded or component using Hibernate Criteria api

Hi! I have this class mapped as a entity, lets call it Person. Person has an embedded/component relation to Address. I am having trouble using a Criteria that would return Address objects. I have tried this: Criteria.createCriteria(Address.class) Which does not work. I guess I need to go through the entity but then I would need some...

How to build HQL query, thats joins subtables marked LAZY, automatically?

I have some entity: public class Album extends GenericAuditedEntity { @OneToMany(fetch = FetchType.LAZY) private Set<Item> itemSet = new HashSet<Item>(); } And when i run HQL like this: em.createQuery("select a from Album a").getResults() it produses many SQL queries: One for select data from Album's table. Smth like thi...