hibernate

I have a feeling that adding fields marked with @Transient annotation to entity is very bug-prone. Am I right?

I have some philosophical intuitive feeling that adding fields which doesn't mapped to the DB corrupts entity classes and is a wrong way of solving problems. But are there any concrete situations where using @Transient fields leads to implicit and hard fixing problems? For example, is it possible that adding or removing 2nd level cache...

Locale based validation

Hi , My project have two main requirements 1) Different set of rules applied to same object at insertion and while updating it. 2) Different validation rules based on locale. In ADDRESS object STATE field requires different validation rules For USA: STATE cannot be NULL. For everywhere else it can be NULL. For first requirement i am...

Hibernate - Persisting polymorphic joins

Hi I'm trying to understand how to best implement a polymorphic one-to-many in hibernate. Eg: @MappedSuperclass public class BaseEntity { Integer id; // etc... } @Entity public class Author extends BaseEntity {} @Entity public class Post extends BaseEntity {} @Entity public class Comment extends BaseEntity {} And now, I'...

Grails automatic constraint update

Does grails have an automatic constraint update. If we change the field in domain class to be nullable by adding constraint, it is not getting reflected in database without schema export. Is it possible to do get grails do this update automatically. ...

Hibernate second level cache - When can stale collection members be returned from the second level cache?

A colleague of mine and I have been having a debate as to when (if?) a collection cached in the second level cache can return stale data (we're using ehcache and hibernate 3.2.4 ). Here's the scenario: parent object P is cached and is an entity. Parent has a collection (bag) of children which are cached and lazy. Children objects C...

Managing Strategy objects with Hibernate & Spring

This is a design question better explained with a Stack Overflow analogy: Users can earn Badges. Users, Badges and Earned Badges are stored in the database. A Badge’s logic is run by a Badge Condition Strategy. I would prefer not to have to store Badge Condition Strategies in the database, because they are complex tree structure objects...

Are there any modeling tools that help visualize how a 3NF model would look like against EAV?

Would like to find low-cost relational modeling tools that will allow me to map a logical model in third normal form to a physical model based on EAV. Got any pointers? ...

Hibernate noob fetch join problem

Hi all I have two classes, Test2 and Test3. Test2 has an attribute test3 that is an instance of Test3. In other words, I have a unidirectional OneToOne association, with test2 having a reference to test3. When I select Test2 from the db, I can see that a separate select is being made to get the details of the associated test3 class. Thi...

How to test if a table is empty, using Hibernate

Using Hibernate, what is the most efficient way to determine if a table is empty or non-empty? In other words, does the table have 0, or more than 0 rows? I could execute the HQL query select count(*) from tablename and then check if result is 0 or non-0, but this isn't optimal as I would be asking the database for more detail than I re...

Java Mvc And Hibernate

Hi i am trying to learn Java, Hibernate and the MVC pattern. Following various tutorial online i managed to map my database, i have created few Main methods to test it and it works. Furthermore i have created few pages using the MVC patter and i am able to display some mock data as well in a view. the problem is i can not connect the tw...

Avoiding secondary selects or joins with Hibernate Criteria or HQL query

I am having trouble optimizing Hibernate queries to avoid performing joins or secondary selects. When a Hibernate query is performed (criteria or hql), such as the following: return getSession().createQuery(("from GiftCard as card where card.recipientNotificationRequested=1").list(); ... and the where clause examines properties that ...

Tomcat, Hibernate and the java.io.EOFException

Hi, My Java application, which uses Hibernate and it's hosted by Tomcat 6.0, gets the following exception after a long time of inactivity when it tries to access the DB: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.io.EOFException STACKTRACE: ja...

Why does HIbernate require no argument constructor?

The no-argument constructor is a requirement (tools like Hibernate use reflection on this constructor to instantiate objects). I got this hand-wavy answer but could somebody explain further? Thanks ...

Hibernate entities stored as HttpSession attribute values

I'm dealing with a legacy Java application with a large, fairly messy codebase. There's a fairly standard 'User' object that gets stored in the HttpSession between requests, so the servlets do stuff like this at the top: HttpSession session = request.getSession(true); User user = (User)session.getAttribute("User"); The old user authe...

update hibernate framework in netbeans

Hi all, what is the best way to update hibernate in netbeans ide to final 3.5.2 version? ...

Remove then Query fails in JPA/Hibernate (deleted entity passed to persist)

I've got a problem with the removal of entities in my JPA application: basically, I do in this EJB Business method: load photo list ; for each photo { //UPDATE remove TagPhoto element from @OneToMany relation //DISPLAY create query involving TagPhoto ... } and this last query always throws an EntityNotFoundExceptio...

How do I configure the hbm2java maven2 plugin to generate POJOs for all mapping files

Hi. I am trying to migrate my ant build to maven2. in my build.xml I invoke the hbm2java in the following way: <hibernatetool destdir="/src/generated/"> <configuration configurationfile="${env.ITP_HOME}/core/xml/hibernate/hibernate.cfg.xml"> <fileset dir="/xml/hibernate"> <include name="*.hbm.xml"/> ...

Hibernate using OneToOne

I have two tables tab1 { col1 (PK), col2, col3 } tab2 { col1, col2(PK), col3 } I am using Hibernate annotation for joining using "OneToOne" I have the below Hibernate class for tab1 class tab1 { @OneToOne @JoinColumn(name = "col2", referencedColumnName = "col1") private tab2 t2; } i was expecting to run the below sql se...

Hibernate Criteria for elements inside a Set

Hi, I have one entity that contains a set of another entity. Entity1 contains Set entityTwos I want to create a search criteria for an "id" field inside entityTwos. I searched, but didn't get any answers. Anybody have an idea? Thanks, Sri ...

How to declare different non-JPA annotations on embedded classes

@Embedded public class EmbedMe { private String prop1; private String prop2; } @Entity public class EncryptedEmbedded { @Embeddable private EmbedMe enc; } I am current using Jasypt for encryption. Is there a way to indicate that the @Embeddable in EncryptedEmbedded will use @Type(value = "newDeclaredTypeHere") per attr...