hibernate

Hibernate Named Query with Join issue

I am trying to create a named query which joins a two tables based on an id. I am getting a HibernateException saying "errors in named queries: Users.getAllUsers the Users bean has a private Set image variable. The UserImages bean is mapped to a table with the images for all the users. This is my named query. @NamedQueries ({ @Name...

HIbernate overwrite data when persist/save entity

I am new in Hibernate.when i save particular entity then it rewrite data from existing one. I have used ID as auto generated as below: @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id") private int id; Here i save Entity as below: class StudDAO() { public static void main(String[] args){ StudDAO obj = new Stu...

HBM2DDL -- Create a database view instead of a Table?

All, Is there some setting that I can tell hbm2ddl to run a view creation statement instead of create a table when generating the database schema? I'm creating my database schema using the wonderful hbm2ddl tool, but I have one issue. I need to flatten some of the tables into views to aid searching the database, and hql would be over...

plain jdbc and hibernate

Hello! I have a project running live for couple of years and it uses plain jdbc. Now I have to implement a small module for which I am considering hibernate. I configured hibernate(hibernate-cfg.xml) and its up n running.So I have DB properties defined in two places oracle-ds.xml and hibernate-cfg.xml 1.Is that OK to mix jdbc,hibernate ...

Tomcat 5.5 OutOfMemory error using Hibernate

I'm experiencing a OutOfMemory error from Tomcat. This error started ever since I added Hibernate into the application. I'm not using Spring, so I do all the open/close for Hibernate Sessions. Below are a few Hibernate configs that I'm using. I create my SessionFactory in the Java code. hibernate.current_session_context_class=thread h...

hibernate spring: PrePersist the place for business-logic?

Hi, I am using Spring + Hibernate to create and store a record in a MySQL database. Just before persisting a record I want my system to generate a random-string which will be stored in a field in the entity that is being stored. This random-string of characters will be used later as an access-key to retreive the record and confirm the ...

DB Connection with MySQL via Hibernate on Embedded Glassfish

Hi! I have a problem to connect my MySQL Database via Hibernate/ JPA2 on a Embedded Glassfish. My Environment: Maven 2 Embedded Glassfish (integrated via Maven Plugin) Eclipse + M2Plugin Hibernate 3.5.6 MySQL (@localhost) (runs and can be connected without container via Hibernate Sessionfactory) Here is my Exception Stacktrace duri...

hibernate auto_increment getter/setter.

Hi, I have a class which is mapped to a table using the hibernate notations of auto increment. This class works fine when I set values and update this to the database and I get a correct updated value in the table. But the issue is when I create a new object of this class and try to get the id, it returns me a 0 instead of the auto_inc...

Hibernate returns null unitilzed Collection

I have two tables, users and images which need to be joined. there is exactly one user row in the users table to many images in the images table. In my users bean I have a private Set variable with a @OneToMany relationship it looks like this //Users.java @Entity @Table(name = "users") @NamedQueries ({ @NamedQuery(name = "Users.getUser...

Named query not known - Annotations & Hibernate

I am getting the following exception: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: Entity class header: @Entity @NamedNativeQuery( callable = true, name = "_Foo_SP", query = "call _Foo()", readOnly = true, resultClass = Foo.class ) public class Foo { //...properties omitted for brevity } In...

DAO vs ORM(hibernate) pattern

Hi all, i read in some articles DAO is not mandatory with hibernate and its implementation is by "it depends", in other words, we can choose between ORM vs DAO pattern. Ok, let's assume that i don't want use a DAO pattern, so im using only session CRUD and query operation provided by hibernate(my ORM). Especially for the "search" and "...

Tomcat server exception - java:comp is not bound in this Context

In doing something else, I added a jar to my lib folder called catalina.jar . This allowed me to serve static content (which works), but my previously working struts actions (which access a database through hibernate) no longer work. The first indication of failure occurs on tomcat startup: SEVERE: Null component Catalina:type=DataSourc...

Can anyone tell why this JPA criteria query generates an invalid SQL statement when executed (Hibernate) and how to fix it?

Hi! I'm having a hard time constructing a criteria query to get the "permissions" attribute from the Role entity with id = 2. The permission attribute is of Set type, so I'm creating a join and selecting from it, but the query fails with invalid grammar exception reporting "Unknown column '2L' in 'where clause'" The criteria query that...

org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize;

I am getting the following error org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize All my classes implements serializable. Acutally I am fetching one list from DB and using it's value to fetch another result. ...

OpenEJB with Tomcat and Hibernate and JPA

Hi there! I'm using OpenEJB 3.1.3 embedded in Tomcat 5.5.26 and I use hibernate 3.6 as a JPA provider. Here's my persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

Hibernate Search + GWT + Hibernate

Hey hey :-) ps: I'm novice with hibernate search This is the morning question. I got one application running with gwt+hibernate. I need to add hibernate search in the application. I took care of this application but all the system was already in place and running. I can see on the entity level, that no @id annotation is used to defin...

controll the hibernate session(when to close it manually)

I am new in hibernate,after read the hibernate api and tutorial,it seems that the session should cloesd when not used. Like this: Session sess=getSession(); Transcration tx=sess.beginTranscration(); //do something using teh session sess.save(obj); tx.commit(); sess.close; I have no question when using it in a standlone application. ...

Run code after Hibernate updates database schema?

Hi Is there a way to register some kind of SchemaExportEventListener (that's a name I've chosen) with Hibernate, so that after it has generated the DDL we can make some updates (which Hibernate doesn't support) to the database? We need to set a case-insensitive unique constraint on a PostgreSQL column, and while this is perfectly possi...

Case insensitive search in hibernate without criteria

I want to do case insensitive search in hibernate Query. I can do it with Criteria but it is not an option for me right now. The method which fire query takes a query string as input and it is used by other components. Is it possible to enable case insensitive for Hibernate session or prepare criteria object from hql query. ...

How can i handle exception from mysql comming when mysql service is down

I am working with mysql5 and hibernate. I am running my application in tomcat application server. if i stop mysqld service for some seconds, i am getting exception: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect If i will start service again, old hibernate se...