hibernate

SQL Server Conversion Exception: Error converting data type varchar to numeric

I am working on a project where the goal is to convert an existing application to SQL Server. However, I am running into issues with ID generation - specifically, the conversion of data types. The hibernate annotations for my ID column are as follows: @Id @GeneratedValue(generator="ID_GEN", strategy=GenerationType.TABLE) @TableGenerato...

EntityManager.find can't find entity, but using the Criteria API does

I've encountered a rather odd case in Java EE 6 where using the JPA EntityManager's find method along with an entity's primary id returns null, but using the Criteria API to select all entities with that id works fine. Here is the code I'm using for find: // Always returns null, even for records I know for sure are in there. user = em....

Hibernate query with partial key

I have two database tables, both mapped using Hibernate. The first table has a primary key with one field. The second has a composite primary key with three fields. Suppose I try to fetch results from the second table by providing just the partial key (one field), then I get an exception Exception in thread "main" org.springframework.o...

JPA - transactions not being commited

Hey guys, i'm working on a project in which i use JPA, Hibernate and all this stuff for the first time and i ran into problem with transactions not being commited. I use class User which looks like this: package org.tomasherman.JBTBackup.Resource.Entity; import javax.persistence.*; import java.io.Serializable; @Entity @Table(name ...

Query Subset of Columns with Gorm

Suppose I have the following Domain class: class Book { String title String author byte[] largeCoverArtImage } I have a list view where I do not need to display largeCoverArtImage, how can I perform the following SQL query using GORM Criteria? select title, author from Book ...

How do you handle Hibernate Session in Business Layer?

How do you handle Hibernate Session in Business Layer? Do you tie your Business Layer to native Hibernate API? (e.g. use session.load() in UserService.java) Any design pattern for Business Layer? Best Practices? I'm using hibernate-core 3.5.3-Final, Spring MVC 3.0.3.RELEASE. ...

Removal of foreign key constraints, Referential integrity and Hibernate

Hi, My colleague mentioned that our client DBA proposed the removal of all foreign key constraints in our project Oracle DB schema. Initially I did not agree with the decision. I am a developer not a DBA. So later realized that there could be some reasons behind the decision. So I am trying get the pros and cons of this decision. Proj ...

Inheritance strategy in Hibernate: making an entity abstract and replacing with sub classes

I have currently existing database and hibernate mapping for it. There is a central table and corresponding entity (PersistentObject). Many of the other tables and entities refer to PersistentObject via @ManyToOne or @OneToOne mapping. Now I'd like to make current PersistentObject abstract and introduce two sub classes Sub1Object and Su...

Hibernate datasource trouble

Hi I have a mysql database from which i got netbeans to generate some entities. Netbeans also automatically generates the persistence.xml, sun-resources.xml and hibernate.cfg.xml file. I am new to hibernate so I don't know much about setting it up. All I know is that right now it isn't working and I have tried loads of things which does...

Specifying restrictions "unique together" in Hibernate

I have an entity where I want to specify a restriction that two fields should have a unique pair value. E.g. one field is owner, another is name, I want a restriction that the combination of (owner,name) should be unique. But I do not want to make these a composite primary key: @Entity @Table(name="keyfile") public class KeyFile { @...

Seam Hibernate Cannot open Connection

I am trying to create a menu. And, for some reason I get "org.hibernate.exception.GenericJDBCException: Cannot open connection" error, but same project works just fine on my desktop, I don't get it. Here is the stack trace: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connect...

How can I do bi-directional mapping over @Any annotated property?

In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question http://stackoverflow.com/questions/217831/how-to-use-hibernate-any-related-annotations, how @Any annotation can be used was explained. But how can I get borrows for each DVD/VHS/BOOK? How can I do mapping definition on DVD/VHS/BOO...

Hibernate and Concurrency.

I have already read the hibernate docs about concurrency and I think, I have understood the available locking methods, but I am not sure how I should implement the following scenario. Two clients F (fast) and S (slow) access the database and can modify the same objects. Now, one additional requirement: It is critical to the application...

How to integrate Spring ,JSF and hibernate

I'm trying to integrate spring with jsf portlet that uses hibernate.I just want to use spring DAO to get the best of spring transaction management. How could I do this in a simple way? It's worth to mention that I'm using ant. Thanks ...

Mapping a ManyToMany relationship with hibernate annotations?

Table Layout: TABLE ORDER: id localizedInfoId Table OrderLocalizedInfo: id localizedInfoId name With the following entities: public class Order { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="id") private Long id; @ManyToMany( targetEntity=OrderLocalizedInfo.class, cascade...

Using Hibernate with Spring 3

My current web development tool is Spring 3, I've used Hibernate before, I'm actually quite familiar with it after I have access to the annotations and entities, and the session object. However, this will be my first time needing to actually set it up from scratch. Currently I have a datasource that I have used for JDBCTemplate, and I ...

Hibernate, MySQL and table named "Repeat" - strange behaviour.

I am having a strange problem. But first the orm.xml: <entity class="de.test.businessobjects.Repeat"> <table name="repeat"/> <attributes> <id name="id"> <generated-value strategy="TABLE"/> </id> <many-to-one name="repeatType" fetch="LAZY"> <join-column name="id_repeatType"/> ...

Dynamic Table creation in Hibernate Template

I am importing stock quotes data using HibernateTemplate + SpringFramework Format of the data AAPL,09-Jun-2010 09:00,251.47,251.47,251.39,251.39,640 AAPL,09-Jun-2010 09:01,251.4,251.4,251.05,251.26,6844 INTC,09-Jun-2010 09:00,251.47,251.47,251.39,251.39,640 INTC,09-Jun-2010 09:01,251.4,251.4,251.05,251.26,6844 MSFT,09-Jun-2010 09:00,25...

struts2 full hibernate plugin

Hi, I was wondering how can I validate fields in action classes' validate method? Because full-hibernate-plugin requires default package to extend "hibernate-default". So, would param intercept and validate? http://code.google.com/p/full-hibernate-plugin-for-struts2/wiki/2_Hibernate_Validator_integration public class Services { @S...

Can this be done using a Hibernate Filter?

In my application I have Documents and Comments. A Comment belongs to exactly one Document, a Document can have several Comments. I have a fairly complicated named query on my Documents: <query name="public.documents"> <![CDATA[ from Document d join d.someOtherProperty join ... where ... ]]> </query> The...