hibernate

How to order by list Index in HQL query?

This is situation I have: I have two entities with one-to-many relationship mapped like that (only relevant parts are given): <class name="xyz.Survey"> <list name="answers" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan"> <key column="OPA_OP_ID" not-null="true" /> <list-index c...

JPA2 + Hibernate + Order By

Hi. Is it possible (using Hibernate and JPA2 Criteria Builder [1]) to order by a method's result rather than an entity's member? public class X { protected X() {} public String member; public String getEvaluatedValue() { // order by return "a status calculated with various members"; } } What I want to achive ...

Difference between FetchType LAZY and EAGER in Java persistence?

Hi I am a newbie to Java persistence and Hibernate. What is the difference between FetchType LAZY and EAGER in Java persistence? Thanks ...

MySQL NDB Cluster + Hibernate

Does anyone know if you can use mySQL Cluster with Hibernate? ...

Spring transactions not committing

I am struggling to get my spring managed transactions to commit, could someone please spot what I have done wrong. All my tables are mysql InnonDB tables. My RemoteServiceServlet (GWT) is as follows: public class TrainTrackServiceImpl extends RemoteServiceServlet implements TrainTrackService { @Autowired private DAO dao; @Override ...

Query Level 2 Caching throwing ClassCastException

Hi, I am using JPA and Hibernate for the database. I have configured (EHCacache) second level cache and query level cache, but just to make sure that caching is working I was trying to get the statistics which is throwing class cast exception.Any help will be highly appreciated. My main goal is to see all the objects which have been ca...

How to get around LazyInitializationException in scheduled jobs?

I am working on a J2EE server application which is deployed on Tomcat. I use Spring source as MVC framework and Hibernate as ORM provider. My object model has lot of Lazy relationships (dependent objects are fetched on request). The high level design is like Service level methods call a few DAO methods to perform database operation. The ...

Java persistence Question

Hi I am new to Java persistence. Does it matter where I put the Annotations at? Are the following two sets of the code the same? Thanks a lot!! @Entity @Table(name="user", schema="billing") public class User { private long id ; private String userName ; private String password ; @Id @GeneratedValue public lon...

JPA/Hibernate Polymorphic Query with @Any

Hi there, I have a jpa mapping class with a polymorphic association like the following: @Entity class MyEnt { private Long id; private MyInterface mi1; private MyInterface mi2; //... @Any(metaColumn = @Column(name = "mi1_type")) @AnyMetaDef(idType = "long", metaType = "string", metaValues = { @MetaValue(valu...

How to extract actual entity and property name that is a duplicate from Hibernate ConstraintViolationException

I would like to be able to extract the entity and property from the ConstraintViolationException message in a rdbms neutral way... Can this be done ? if so how ? ...

When to use Hibernate?

Hi All, I was asked in an interview this question so I answered with the following: -Better Performance: - Efficient queries. - 1st and 2nd level caching. - Good caching gives better scalability. - Good Database Portability: - Changing the DB is as easy as changing the dialect configuration. - Increased Developer Productivity: ...

How to solve following issue in java?

Im getting following error while running the query. org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found 'LIMIT' near line 1, column 194 [from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' and gpsdate in (select id.gpsdate from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' ORDER BY id.gpsdat...

How to convert SQL- Query with subselect into HQL Query?

I would like to convert following Query into HQL Query. How can i do? select * from gpsdata where mobileunitid = '2090818044' and gpsdate in (select gpsdate from gpsdata where mobileunitid = '2090818044' ORDER BY gpsdate DESC LIMIT 1 ) and gpsstatus='true' ...

Change default polymorphism in Hibernate

Hi, I'd like to set polymorphism="explicit" property to several hibernate mapping classes. is it possible to override the default implicit value, so that I do not need to set explicit in multiple classes? <class name="xxxxx" table="XXXXX" polymorphism="explicit"> I am using hibernate mapping xml files (No annotations or JPA) and it w...

HQL: Union selects

Hi guys, I have a forum-like system where a user has an access group and a post can be accessed by an access group. A post is of a category type, and I'd like to make a list of the category names with the number of posts the user has written in this category in a paranthesis. A user may not have access to all his posts, because one acce...

Hibernate - Restriction for class in a list

I'm trying to pull back a list of items that have a specific type of item in a set. For example: <class name="Owner" table="OWNER"> <id name="id" column="OWNER_ID" /> <set name="cats" table="OWNER_CATS" lazy="false"> <key column="OWNER_ID" /> <many-to-many class="Cat" /> </set> <class name="Cat" table="CAT" discriminator-v...

Criteria hibernate

my code session.createCriteria(Input.class); DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date startDate = (Date)format.parse("2005-01-01 00:00:00"); Date endDate = (Date)format.parse("2005-03-03 00:00:00"); crit.add(Expression.between ("inputDate", new Date(startDate.getTime()), new Date...

generating class from hibernate mapping file

hi, i have one mapping file viz. student.hbm.xml.. i need to generate Student.java from the same. the file is below :- <?xml version="1.0" encoding="UTF-8"?> <hibernate-mapping> <class name="org.hibernate.entity.ClassRoom" table="class_room"> <id name="roomId" column="room_id" type="int"/> <property name="roomClass" ...

implementing dynamic class with using hibernate annotation

Hi. I want to implement a class which its fields could change (add new fields) through time. The problem is that I want to give my client this ability to do this himself by just completing a form of what field and which type he wants and then the change will be done automatically! Does anyone have any idea how can I implement this class...

MySQL Datetime <-> Java Date

Hello! I use Hibernate and I have a datetime in my MySQL database. Now I want to store the date/time which is a java.util.Date into the database. So I can write: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); testObject.setCreationDate(df.parse("2010-06-06 13:20:15")); But how can I set the current date/time? Bec...