hibernate

Spring/Hibernate: InvocationTargetException when deleting entity

I'm sorry if this question is a bit vague, but I'm quite confused. I've got a controller that calls a service to delete an entity and then create an entity in its place. In the service, I've got my DAO, and my entity, and I want to delete my entity, so I call DAO.delete(entity); Then, seemingly out of nowhere, I get an InvocationTarg...

How to configure hbm2java and hbm2dao to add packagename to generated classes

Hi, I'm trying to configure hbm2java with maven to generate POJO classes and DAO objects. One of the issues I'm dealing with is package names aren't generated. I'm using the following pom for that: <execution> <id>hbm2java</id> <phase>generate-sources</phase> <goals> <goal>hbm2java</goal> </goals> <inherited...

Pros and cons of sorting data in DB?

Let's assume I have a table with field of type VARCHAR. And I need to get data from that table sorted alphabetically by that field. What is the best way (for performance): add order by field to the SQL-query or sort the data when it's already fetched? I'm using Java (with Hibernate), but I can't tell anything about DB engine. It could...

HQL specify an order by property order?

How can I order by a specific property order in HQL? For MySQL I can use: SELECT * FROM question q ORDER BY q.status IN ("DONE", "NO_ACTION"), q.status IN ("NEW","SAVED"), q.created DESC but HQL doesn't allow in in order by. Am I missing something? Is there some other way around this problem? Thanks ...

Eager loading OneToMany in Hibernate with JPA2

I have a simple @OneToMany between Person and Pet entities: @OneToMany(mappedBy="owner", cascade=CascadeType.ALL, fetch=FetchType.EAGER) public Set<Pet> getPets() { return pets; } I would like to load all Persons with associated Pets. So I came up with this (inside a test class): @RunWith(SpringJUnit4ClassRunner.class) @ContextConfig...

what does mean "SQL Error: 30000, SQLState: XSAI3" ?

I'm using javadb/derbydb 10.5.3.0 with hibernate 3.5-Final I get this error at the end of EM initialisation : 4427 [SwingWorker-pool-1-thread-1] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 30000, SQLState: XSAI3 4427 [SwingWorker-pool-1-thread-1] ERROR org.hibernate.util.JDBCExceptionReporter - Feature not implemented. ...

Whats wrong with this HQL query?

did i encounter a hibernate bug or do i have an error i dont see: select enty.number from EntityAliasName enty where enty.myId in ( select cons.myId from Consens cons where cons.number in ( select ord.number from Orders ord where ord.customer = :customer and ord.creationDate < ( select max(ord.crea...

Having virtual rows in a table in hibernate.

I'm sure this is a question to which most of the answers will be "Why are you doing that?", but I thought I would ask. I've got a table of (Users), the vast majority of which just have an ID (as they're lazily created users for sessions that have never provided any information), and don't use the rest of the columns in the database. I'v...

Query a Hibernate many-to-many association

In Hibernate HQL, how would you query through a many-to-many association. If I have a Company with multiple ProductLines and other companies can offer these same product lines, I have a Company entity, a ProductLine entity and an association table CompanyProductLine. In SQL, I can get what I need like this: select * from company c wh...

java.sql.SQLException: Unsupported feature

I am using the JPA(hibernate) for the ORM and c3po for connection pooling. While I am able to do all the CRUD operations it gives me the below error while accessing the the data: Here are the tools: Hibernate 3.2.1, Oracle 10g, ojdbc14, connection pool: c3p0-0.9. And the stack trace: java.sql.SQLException: Unsupported feature ...

JPA entities -- org.hibernate.TypeMismatchException

Environment: JDK 1.6, JEE5 Hibernate Core 3.3.1.GA, Hibernate Annotations 3.4.0.GA DB:Informix Used reverse engineering to create my persistence entities from db schema [NB:This is a schema in work i cannot change] Getting exception when selecting list of basic_auth_accounts org.hibernate.TypeMismatchException: Provided id of the wrong...

Hibernate doesn't generate cascade

Hi. I have a set hibernate.hbm2ddl.auto to create so that Hibernate creates the tables in mysql for me. However, it doesn't seem that hibernate correctly adds Cascade on the references in the table. It does however work when I for instance delete a row, and I have a delete cascade as hibernate annotation. So I guess that means that Hib...

[Hibernate] Problem with saveOrUpdate()

Hi, I've problem with Hibernate. I have a class User class User { int id; String name; } where id is native generator in User.hbm.xml , and name is primary-key in DB. In my database , I saved some information about Users. Than, I want to connect with this information about User. For example in my DB i have row INSERT INTO U...

How to get Hibernate object relations dynamically?

Hi, I'm using Hibernate and I need to find a way of retrieving the relations for an object dynamically at run-time. I can't find this in the API. Can anyone point me in the right direction please? Thanks ...

How to create a custom Annotation and processing it using APT ?

Hi, I'm new to Java Annotation. I know how to create custom annotation but I don't know how to process that Annotation to generate the dynamic code just like ejb 3.0 and hibernate does. I read some articles based on APT but no one gives the details about how to process the Annotation. Are there any tutorials with sample code for process...

Grails / GORM, Disable First-level Cache

Suppose I have the following Domain class mapping to a legacy table, utilizing read-only second-level cache, and having a transient field: class DomainObject { static def transients = ['userId'] Long id Long userId static mapping = { cache usage: 'read-only' table 'SOME_TABLE' } } I have a problem, references to DomainObjec...

Hierarchical Hibernate, how many queries are executed?

So I've been dealing with a home brew DB framework that has some seriously flaws, the justification for use being that not using an ORM will save on the number of queries executed. If I'm selecting all possibile records from the top level of a joinable object hierarchy, how many separate calls to the DB will be made when using an ORM (...

How to improve my software project's speed?

I'm doing a school software project with my class mates in Java. We store the info on a remote db. When we start the application we pull all the information from the database and transform it into objects to use in our application (using java sql statemens). In the application we edit some of these objects and then when we exit the app...

Hibernate ResultTransformer with JPA API

Has anyone figured out a smart way to do query result transformation through a similar mechanism like specifying a ResultTransformer in Hibernate? All I can think of is transforming each result row after it has been returned by the Query. Is there any other way? For constructor projections (e.g. new DTO(arg1, arg2)) it can be defined i...

Hibernate is persisting entity during flush when the entity has not changed

I'm having a problem where the entity manger is persisting an entity that I don't think has changed during the flush. I know the following code is the problem because if I comment it out the entity doesn't persist. In this code all I'm doing is loading the entity and calling some getters. Query qry = em.createNamedQuery("Clients.findBy...