hibernate

Using functions as arguments in hibernate aggregation functions

I would like to perform the following query in HQL: select count(distinct year(foo.date)) from Foo foo However, this results in the following exception: org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 27 It seems that hibernate does not allow using functions as arguments to it...

Why is it recommended to avoid unidirectional one-to-many association on a foreign key?

In the Hibernate online documentation, under section 7.2.3 One-to-many, it's mentioned, that: unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended. You should instead use a join table for this kind of association. I would like to know why? The only thing that comes to my mind is...

How to perform a non-polymorphic HQL query in Hibernate?

Hi all, I'm using Hibernate 3.1.1, and in particular, I'm using HQL queries. According to the documentation, Hibernate's queries are polymorphic: A query like: from Cat as cat returns instances not only of Cat, but also of subclasses like DomesticCat. How can I query for instances of Cat, but not of any of its subclasses? I'd li...

Is it a missing implementation with JPA implementation of hibernate??

Hi all, On my way in understanding the transaction-type attribute of persistence.xml, i came across an issue / discrepency between hibernate-core and JPA-hibernate which looks weird. I am not pretty sure whether it is a missing implementation with JPA of hibernate. Let me post the comparison between the outcome of JPA implementation ...

insert hibernate domain objects to different database?

I want to copy all data of a specific table from database1 to database2. In my system i have access via hibernate to the domain object from database1, i don't have to transform the data-structure. i have only a native jdbc connection to database2. whats the best solution to make this groovy script very generally to support all kinds of...

Hibernate doesn't work anymore... why?

Hello, I was doing simple things with hibernate, as I have to learn it for a project. I created this simple example: package hibtests; import hibtests.beans.newBean; import org.hibernate.Session; /** * * @author dario */ public class Main { public void test(){ Session session = NewHibernateUtil.getSessionFactory().ge...

Ajax in hibernate project

Has anybody used ajax in hibernate project ? Any pointers, help will be appreciated. ...

@OneToMany without inverse relationship and without a join table?

This is a similar problem to "Hibernate @OneToMany without a separate join table", in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to result in a join table being automatically generated... is there a workaround for this? ...

Hibernate: How to remove an entity to which none refers to anymore in ManyToOne?

I have two entities, lets call them A and B, which have a ManyToOne mapping to another entity, say C So I typically have something like this: a1->c a2->c b1->c Lots of A's and B's pointing to the same C. How do I get Hibernate to remove c when I remove the last a and b? ...

multiple session factories, one connection?

Hi all, To avoid XA overhead I prefixed some table names from project A and rolled it out to be inside the same mysql database as project B so I can use the same connection - and hope to get full atomicity etc. Project A and B though have very different session factory configs. I have a HibernateTransactionManager configured for projec...

Help with rewriting a HQL query ( Hibernate Query Language )

HQL noob here. How do I re-write this HQL query without using the exists clause. In SQL I can just join VisitorProfileField table and Visitor table and add the conditions of the exists using an AND. But in plain HQL I am not able to get past some syntax violation I guess. Your help is much appreciated. "select distinct v from Visitor...

hibernate criteria OneToMany, ManyToOne and List

Hi, I have three entities ClassA, ClassB and ClassC. ClassA { ... @Id @GeneratedValue @Column(name = "a_id") private long id; ... @OneToMany(cascade={CascadeType.ALL}) @JoinColumn(name="a_id") private List<ClassB> bbb; ... } ClassB { ... @ManyToOne private ClassC ccc; ... } ClassC { ... private String name; ... } I...

Hibernate many-to-many with map collection

I have two tables "Station" and "Route". Route can contain many stations and every station can be a part of the different routes. The logical solution is to create a table with 'station_id' and 'route_id' fields and there are lot of examples on the internet how to organize all of this stuff with hibernate. But I need to store the order n...

Hibernate MySQL transaction configuration issue

I'm having trouble starting a transaction with Hibernate and MySQL while running in JUnit. I'm getting a HibernateException which states: "No TransactionManagerLookup specified". I believe this error is because I don't have a proper configuration setting for hibernate.transaction.manager_lookup_class. I see that under the namespace of ...

I found JPA, or alike, don't encourage DAO pattern

I found JPA, or alike, don't encourage DAO pattern. I don't know, but I feel like that, especially with server managed JTA managers. After adequate hands-on using DAO pattern, I started designing JPA based application around that pattern. But it doesn't fit in, IMO. I tend to lose quite a features of JPA and all. Well, suppose you fire...

I can't understand HQL joins

Hello, I'm starting to work with hibernate. I'm quite confused about HQL joins... they are really different from, say, mySQL joins... In fact if I have two tables like Parking and Auto I would do: select * from Parking left join on Parking.pid = Auto.parkingId or something the like. Instead in hibernate I will have a Parking class alr...

Use two databases concurrently in Hibernate

Hello, I've to use more than one database together (on the same connection... ) via mysql. I want to use hibernate, but all I can find around is to use two sessionfactories. Now the problem is: how can I do mappings like one-to-many among different sessionfactories... seems not possible as I have to put mapping in one configuration and I...

Hibernate: set default query timeout?

I am doing some big queries on my database with Hibernate and I sometimes hit timeouts. I would like to avoid setting the timeout manually on every Query or Criteria. Is there any property I can give to my AnnotationConfiguration that would set an acceptable default for all queries I run? If not, how can I set a default timeout value ...

@GeneratedValue(strategy = GenerationType.SEQUENCE) and startVaule

when using the @GeneratedValue Annotation in Hibernate, and adding a new Entity to DB it has the id 1 ... n . Is is it possible to set the first value, so it would get the id e.g. 10000 ... n ? ...

Hibernate : how to configure the Flush after every RW-D operation ?

I have an AbstractDao implemented by every Dao of my database. public abstract class AbstractDaoImpl extends HibernateDaoSupport { (...) public void delete(T pEntity) throws FerdeDaoException { try { this.getHibernateTemplate().delete(pEntity); } (...) } .... Bascially the flushMode seems to be at AUTO. What do i ...