hibernate

Random ID Generator, mapping vs. same-column

Hi all, There're a few entities that we wish to hide its exact ID from the customers - the main reason is that, we do not want customers to know how many of them are in the DB. e.g. from the URL, http://mydomain/user/get/27, it says that this is the 27th user. Therefore, I am implementing a solution that assigns random ID (that has to...

Hibernate many to one delets all parents when a child is deleted

I have Country and State objects. I intend to have unidirectional many to one relationship from State to Country. I don't want to store any references to States in Country I have defined mapping as below. When I delete even one State object, all Countries are deleted! <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hib...

Hibernate - How to cascade deletes using annotations where only unidirectional child relationship is specified

Supposing I have two entities a parent object and a child. I want the child to have a relationship specified to the parent entity and a reference, but I don't want the parent to have to know about it. The reason for this is there are numerous such relationships and explicitly specifying the relationship for all these children will mean...

Can I automatically update Hibernate pojos and mappings in Netbeans after adding a new table?

I already have hibernate mapping files and pojos created by Netbeans to which I've added named queries and extra methods. Now I've added another table to the database and a foreign key column to an existing table. It's not a big problem with just one table to add the mappings by hand but it gets tedious and error prone with more. What...

hibernate: how to setup on-delete="cascade" in one-to-one relation

i have to table relation one-to-one: message & scheduled_message my hibernate config <class name="Message" table="message"> <id name="id" column="id"> <generator class="native" /> </id> <property name="name" column="name" /> <one-to-one name="scheduled"> </class> <class name="ScheduledMessage" table="sc...

NHibernate: How to exclude a class which is part of a join using the Criteria API

I am still new to Hibernate and am attempting to use it for a web site I have inherited. Unfortunately that means sometimes the db schemas don't always make sense. With that said, I am trying to build the following HQL query using the Criteria API from TableB b where b.id = :id and b.TableAProperty.UserId = :userId The above HQL sta...

With a created by timestamp, is it better to have the DB manage it, or the application?

We have your bog standard Java app under development, and a lot of the records we're creating (Hibernate entities in MySQL) have 'created' and 'modified' timestamps on them. Now, me and one of the developers disagree - I believe that both of those fields should have a MySQL default of CURRENT_TIMESTAMP, and then the modified can be chan...

The fastest way to check if some records in a database table ?

I have a huge table to work with . I want to check if there are some records whose parent_id equals my passing value . currently what I implement this is by using "select count(*) from mytable where parent_id = :id"; if the result > 0 , means the they do exist. Because this is a very huge table , and I don't care what's the exactly num...

Using Spring and Hibernate -final year project

I’m planning to build Management Information System in Java for my final year project. I would like to use Spring and Hibernate, however I haven’t used any of these frameworks yet. Hence my question is, will I have enough time to learn it (I don’t mean to be an expert, just to be able to use them in my project) and still complete my pro...

List of list of named parameters in EJBQL/HQL

I'm trying to execute a long 'INSERT ON DUPLICATE KEY UPDATE' with up to a few thousand rows in a MySQL+JBoss+Hibernate application. It looks something like: INSERT INTO Table (field1, field2, field3) VALUES (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), (value1_3, value2_3, value3_3), ... ON DUPLICATE KEY UPDATE ... ...

Hibernate bi-directional many-to-many cascade confusion

I'm a hibernate newbie and I'm not entirely sure how to get the cascade behavior I'm looking for. Let's say I have two classes A and B with bi-directional many-to-many mappings to each other. A is the owner side and B is the inverse side (I hope I have the terminology correct). public class A { private Set<B> bSet = new HashSet<B>(...

How to setup Hibernate @ManyToMany association with cascades on both foreign keys?

I'm trying to map a @ManyToMany association using hibernate. But so far I only managed to have cascade on one of the foreign keys. My source code goes like this: @Entity public class Airplane { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @OnDelete(action=OnDeleteAction.CASCADE) @ManyToMany(m...

spring hibernate: save form object in relation

i have table users: relation many-to-many with table role, groups i use hibernate to map with my class; <hibernate-mapping package="cbs.domain"> <class name="User" table="users"> <id name="id" column="id"> <generator class="native" /> </id> <property name="username" /> <property name="password" /> <prope...

Converting a HQL-query which includes elements() to Criteria API

I'm having trouble converting the following HQL-query to Criteria API and I was wondering if I could get some help from you guys SELECT child FROM Foo AS child WHERE child IN (SELECT elements(obj.foos) FROM Bar AS obj WHERE obj.id = ?) In other words, I want to fetch all Foos that Bar references to in the instance of Bar whose id ...

Criteria query with restriction across a joined subclass problem

I have the following graph: OrderLine OrderLineExtension OrderLineExtensionA OrderLineExtensionB OrderLineExtensionC OrderLine contains a Set of OrderLineExtension. OrderLineExtension is defined as : @Inheritance(strategy = InheritanceType.JOINED) and is marked as an entity and is abstract A table is creat...

What does GA means in hibernate versions?

What does GA means in hibernate versions? ...

Is there a way to get Hibernate's hbm2ddl Ant task to exclude specific tables?

I use Hibernate to generate my database automatically for testing, and I have some tables in my schema that contain static data that takes a very long time to import. In the past, I've used the following code in my build file to generate the database (from mapping files): <target name="schema-gen" depends="hibernate-gen"> <taskdef n...

JPA/Hibernate with Oracle Label Security

I have an application built with Spring and JPA/Hibernate that is working very well, but I now have a requirement to add Oracle Label Security. This will require the creation of a proxy user assigned with certain roles in addition to the actual user. I am unclear what goes into persistence.xml and what goes in code. Also, if we want to g...

Grails Hibernate H2 problem

hi, I have an application with two domain classes as follows: DomainA : PK, name DomainB : PK, FK (points to DomainA.PK), name. And when I try to list elements that belongs to DomainA using the DomainB.name as order factor, as follows: def listings DomainA.createCriteria().list(params) { PK{ order('name','asc') } }...

JPA Native Query for Entity with Inheritance

I have an entity class and a subclass based on that entity: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class A and @Entity public class B extends A I need to issue a native query that uses a stored procedure on the base class (A) only. If I attempt it as follows: entityManager.createNativeQuery("selec...