hibernate

Should I close connection when using SessionFactoryUtils

If I want to use SessionFactoryUtils to get Connection directly to execute some SQL statement, and join the same transaction. Like this: SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection(); //some logic after Connection retrieved Do I have to close Connection by myself? or just let it be and Hibernate Session will h...

Enable Hibernate "show_sql" for a Nuxeo installation

I want to see why my Nuxeo installation is failing when I point its SQL user directory to other database (Oracle says: table/view doesn't exists). I want to enable show_sql Hibernate parameter to see the sql in the console.. but I don't know where I can do it (if I can). ...

HIbernate loads subclasses along with classes

I am using Hibernate to connect to my database. I have an inheritance structure in my application.The problem is that when i do a query like "from Animal", it does a left outer join for the class Animal,its sub classes and all the associations for Animal and its subclasses. How do i avoid this situation.I want to load the data only when ...

Hibernate query result

I have the following query in my application:v public List getLocation(String id) { List object = null; try { org.hibernate.Transaction tx = session.beginTransaction(); Query q = session.createQuery("from Entrancestolocations as EL left join EL.entrances as E left join EL.location as L where L = " + id); ...

Hibernation annotations, specify column default value

I have a domain object and annotated as follows @Entity @Table(name = "REQUEST") public class Request { /** * Unique id for this request */ @Id @GeneratedValue @Column(name = "EQ_ID") private long requestId; /** * */ @Column(name = "EMAIL_ID") private String emailId; /** * */ @Column(name = "REQUEST_DATE") private Date...

SaxParser errors with Hibernate and JBoss - conflicting versions?

I am using JBOSS 5.1.0.GA and Hibernate when I try to connect to the database I get the following errors 10:21:03,042 INFO [Version] Hibernate Commons Annotations 3.1.0.GA 10:21:03,049 INFO [Configuration] configuring from resource: /hibernate.cfg.xml 10:21:03,049 INFO [Configuration] Configuration resource: /hibernate.cfg.xml 10:21...

Glassfish and java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy with javassist.jar in lib. Why have I this error ?

I want to use Glassfish and hibernate. I use the Glassfish update tool to add the hibernate libraries. So I have all needed libraries. But when I ran my JUnit test I have this exception : java.lang.RuntimeException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy Any idea ? Thanks a lot ...

Hibernate single file databases: setup for thin client

I'm debeloping a Java Swing application, which persists the information through Hibernate, currently using PostgreSQL. Now, I would like to simplify the database setup on the client and I'm thinking about single file databases. The database I'm using is rather small and simple, so there are no special requirements. I'm only asking for on...

Hibernate inheritance with existing tables

Hi, I have 2 existing tables in my database. Let's call them Table and Chair for now. Both these tables are mapped as entities in Hibernate Both these tables have existed in my database for some time now, and they have their own, auto generated, ID's as primary keys. Now however, I want to group those entities under the very logical F...

What is the best database to use with Grails in an enterprise application?

I realize this has flame potential, please refrain. That being said, I'm interested in what databases people have used with Grails. What positive experiences and what horror stories are out there? I love MySQL, but there are a few significant bugs that are impacting me between Hibernate and MySQL, particularly as it pertains to index cr...

How to bind an entity to a specific persistence-unit

In a web application using struts2 ejb hibernate, is it possible to tell the application to find or create an entity for a specific persistence-unit name, which is written in persistence.xml file, in the deployment time? I have two persistence-unit in persistence.xml, and one datasource (including two "local-tx-datasource") xml file un...

Hibernate Auto Increment

I am using hibernate's "increment" generator to generate my auto increment Id's. This was working fine until I had to add another application which also uses the "increment" generator to generate new id's. I realised there is a catch with the increment generator: "generates identifiers of type long, short or int that are unique only wh...

JPA: difference between @JoinColumn and @PrimaryKeyJoinColumn?

What's the exact difference between @JoinColumn and @PrimaryKeyJoinColumn? You use @JoinColumn for columns that are FKs. A typical column could look like (e.g. in a join table with additional attributes): @ManyToOne @JoinColumn(name = "...") private OtherClass oc; What happens if I promote the column to be a/the PK, too (a.k.a. ident...

DOM4J and Hibernate: Dealing with the XML

So my web application is primarily using XML for client to server interaction and I'm currently persisting most of my backend using hibernate. I know there are XML databases and there that you can save XML using hibernate by invoking Sessions with the DOM4J entity but I'm not sure what the most efficient way of serving up the XML really ...

Why is an object found by id in JPA, but not through a JPQL query?

I have a JUnit 4 test case with the Spring @Transactional annotation that saves an object, and then attempts to find it. The test case passes when I use this implementation: @Override public EventSummary findEventSummaryById(Integer id) { return em.find(EventSummary.class, id); } It fails when I use this implementation (and then c...

JPA: When to choose Multivalued Association vs. Element Collection Mapping

I would like to better understand the differences between (1) a traditional Multivalued Relationship/Association @Entity -> @OneToMany -> @Entity and (2) the JPA2 Collection of Embeddable (and basic) Types @Entity -> @ElementCollection -> @Embeddable I see the syntactical differences, but wonder whether there are also ...

grails and mysql batch processing

I'm trying to implement the advice found in this great blog post for batch processing in grails with MySQL. The problem that I'm having is that inclusion of periodic calls to session.clear() in my loop causes org.hibernate.LazyInitializationException's to be thrown. There's a quote down in the comments section of the page: You’re sec...

Grails - how to enforce at least one in a one to many relationship

Hi, Please can you help with the example below: class Car { static hasMany = [cd:Cd, fluffyDice:FluffyDice, wheel:Wheel] } class Wheel{ static belongsTo = [car:Car] } How do I enforce that a car has at least one wheel? ...

Per-user TimeZones in a webapp using Spring

Hello, I have a web application which has different users logging in to view transactions. I want to be able to let the users set their own time zone and then have dates on forms be bound using the user's timezone so that they can search transactions in a database and have the results adjusted depending on what time zone the user is in...

Is it possible to *transform* the type of a polymorphic Hibernate/JPA entity?

UPDATE: after posting, I discovered this is a duplicate of this older question. I have an odd business requirement: my application supports users getting started as "Guests", then later registering to become "Registered" users. Guests are feature-restricted: they are not allowed to access some functionality that is available once the...