hibernate

How can I resolve Hibernate 3's ConstraintViolationException when updating a Persistent Entity's CollectionOfElements?

I'm trying to discover why two nearly identical class sets are behaving different from Hibernate 3's perspective. I'm fairly new to Hibernate in general and I'm hoping I'm missing something fairly obvious about the mappings or timing issues or something along those lines but I spent the whole day yesterday staring at the two sets and an...

Automatically Add a Prefix to Column Names for @Embeddable Classes

I am developing a project in which I am persisting some POJOs by adding Hibernate annotations. One problem I am running into is that code like this fails, as Hibernate tries to map the sub-fields within the Time_T onto the same column (i.e. startTime.sec and stopTime.sec both try to map to the colum sec, causing an error). @Entity publi...

Database connection timeout

Hi I have read so many articles on the Internet about this problem but none seem to have a clear solution. Please could someone give me a definite answer as to why I am getting database timeouts. The app is a GWT app that is being hosted on a Tomcat 5.5 server. I use spring and the session factory is created in the applicationContext.xm...

How to make safe frequent DataSource switches for AbstractRoutingDataSource?

I implemented Dynamic DataSource Routing for Spring+Hibernate according to this article. I have several databases with same structure and I need to select which db will run each specific query. Everything works fine on localhost, but I am worrying about how this will hold up in real web site environment. They are using some static cont...

What is the fastest findByName query with hibernate?

I am sure I can improve the performance of the following findByName query of hibernate: public List<User> findByName(String name) { session.createCriteria(User.class).add(Restrictions.eq("name", name)).list(); } The bottleneck is that findByName method and I cannot use the id instead. In my case I know that the name is unique but a...

Understanding Hibernate saveOrUpdate and the Persistence Life Cycle

Let's look at a simple example of a dog and a cat that are friends. This isn't a rare occurrence. It also has the benefit of being much more interesting than my business case. We want a function called "saveFriends" that takes a dog name and a cat name. We'll save the Dog and then the Cat. For this example to work, the cat is going ...

Hibernate Save Parent Only

Hi, I'm having an issue with Hibernate 3.2.5, where I have to save only the parent object in a one-to-many relationship. For example, I have a flower A, that can have many details. Firstly I want to save only the flower, and the details will be added later. This process throws an exception: not-null property references a null or trans...

Deleting JPA entity containing @CollectionOfElements throws ConstraintViolationException

I'm trying to delete entities which contain lists of Integer, and I'm getting ConstraintViolationExceptions because of the foreign key on the table generated to hold the integers. It appears that the delete isn't cascading to the mapped collection. I've done quite a bit of searching, but all of the examples I've seen on how to accomplis...

How to disable sql creation for JPA entity classes

We have some JPA entity classes which are currently under development and wouldn't want them as part of the testing cycle. We tried commenting out the relevant entity classes in META-INF\persistence.xml but the hbm2ddl reverse engineering tool still seems to generate SQL for those entities. How do I tell my code to ignore these classes? ...

Hibernate criteria

hi i have a query i got a list from Criteria in hibernate. after that i want to add a condition on that list can i do that ...

What is the best way to launch HSQLDB for unit testing, when working with spring, maven and hibernate?

In my project I can successfully test database code. I'm using Spring, Hibernate, HSQLDB, JUnit and Maven. The catch is that currently I have to launch HSQLDB manually prior to running the tests. What is the best way to automate the launching of HSQLDB with the technologies being used? ...

Is checking no.of rows before fetching them more efficient than directly fetching all data in hibernate?

I have below scenario Got n as minimum number of database required for the transaction. Issue select count(*) query to find out number of rows satisfying the criteria. if the result of step 2 is greater than or equal to n, then proceed further or throw exception. Fetch actual objects by limit to n in hibernate query. do the logic and s...

Hibernate MapKeyManyToMany gives composite key where none exists

I have a Hibernate (3.3.1) mapping of a map using a three-way join table: @Entity public class SiteConfiguration extends ConfigurationSet { @ManyToMany @MapKeyManyToMany(joinColumns=@JoinColumn(name="SiteTypeInstallationId")) @JoinTable( name="SiteConfig_InstConfig", joinColumns = @JoinColumn(name="SiteConfigId"), inve...

Seam + hibernate + jsf on weblogic

I'm making a little project with Seam, Hibernate and JSF. This project run on JBoss 5.1. My boss wants to deploy this project on WebLogic. I read on the seam documentation that seam and WebLogic don't work fine together. I would like to know if I can use Hibernate (with JPA) and JSF on WebLogic and what framework (struts, spring?) I ca...

How can we compute the LAST page with JPA?

I would like to implement pagination in my Servlet/EJB/JPA-Hibernate project, but I can't figure out how only one page from the query and know the number of pages I must display I use setFirstResult(int first) ; setMaxResults(int max) ; and that's working alright, but how can I know how many pages I will have in total? (Hibernate i...

Pessimistic locking is not working with Query API

List esns=session.createQuery("from Pool e where e.status=:status "+ "order by uuid asc") .setString("status", "AVAILABLE") .setMaxResults(n) .setLockMode("e", LockMode.PESSIMISTIC_WRITE) .list(); I have the above que...

Should we use LockOptions instead of LockMode in hibernate query?

I see two classes for locking in hibernate 1. LockOptions 2. LockMode What is the difference between two? When to use each? ...

Refresh of an Enity with a colllection throws a UnresolvableObjectException when an Element of the collection got deleted

We have a two tier Swing application using Hibernate. Sometimes we manipulate an object in one session (A), which we know in another session (B) as well (two different Java Instances, same database record). In this case after commit and closing of A, we refresh the object in session B, in order to show the updated state in the UI. Works...

Hibernate exception when starting Tomcat (after upgrade to hibernate-3.5.0)

I'm getting the following exception when starting a tomcat instance with my web app after upgrading to hibernate 3.5.0: org.hibernate.annotations.common.AssertionFailure: Fail to process type argument in a generic declaration. Type: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl at org.hibernate.ejb.metamodel.Attri...

How to enforce lazy loading of entities on certain conditions

We have an JPA @Entity class (say User) which has a @ManyToOne reference (say Address) loaded using the EAGER option which in turn loads it's own @ManyToOne fields (say Country) in a EAGER fashion. We use the EntityQuery interface to count the list of User's based on a search criteria, during such a load all the @ManyToOne fields which ...