hibernate

Problem with 2 levels of inheritance in hibernate mapping

Here's my class structure: class A class B extends A class C extends A class D extends C class E extends C And here are my mappings (class bodies omitted for brevity): Class A: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @MappedSuperclass @DiscriminatorColumn( name="className", discriminatorType=Discr...

What is best practice about having one-many hibernate

Hi all, I believe this is a common scenario. Say I have a one-many mapping in hibernate Category has many Item Category: @OneToMany( cascade = {CascadeType.ALL},fetch = FetchType.LAZY) @JoinColumn(name="category_id") @Cascade( value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN ) private List<Item> items; Item: @ManyT...

Create Custom values for the cells in the YUI datable or gui: dataTable

Hi i would like to know how to create custom values for the dataTable. For example I want to do some calculations for the values that will be placed in the dataTable. But what happens is that I get an error: ERROR errors.GrailsExceptionResolver - Executing action [dataTableJSON] of controller [com.MeetingController] caused exception: ...

Coalesce equivalent in Hibernate Criteria query?

Hi everyone, I want to write the following query as a Hibernate Criteria query: select to_char(nvl(ol.updated_datetime, ol.created_datetime), 'dd/mm/yyyy'), sum(discount_price) from order_line ol where nvl(ol.updated_datetime, ol.created_datetime) between to_date('05-may-10') and to_date('30-may-10') group by to_cha...

Good design of mapping Java Domain objects to Tables (using Hibernate)

Hey guys, I have a question that is more in the realm of design, than implementation. I'm also happy for anyone to point out resources for the answer and I'll gladly, research for myself. Highly simplified Java and SQL: Say I have a business domain POJO called 'Picture' with three attributes. class Picture int idPicture Str...

Putting BigDecimal data into HSQLDB test database using DbUnit

Hi everyone, I'm using Hibernate JPA in my backend. I am writing a unit test using JUnit and DBUnit to insert a set of data into an in-memory HSQL database. My dataset contains: <order_line order_line_id="1" quantity="2" discount_price="0.3"/> Which maps to an OrderLine Java object where the discount_price column is defined as: @Co...

Question on XJB

I have two tables -- INSTALL_BUILD_RESULTS and BUILD_RESULTS. IBR has a primary key called Install_Build_Id and BR has a primary key called Build_Id. Both are numbers A third table, LINK_BUILD_TO_INSTALL_BUILD is a table simply consisting of the two columns mentioned above, used together as a composite key. How can I write an xjb for ...

I'm using spring, hibernate and mysql. How can I let my app create the table automatically.

Hi guys, I'm using spring, all my annotated entity class information are put in the ApplicationContext.xml. I'm using a MySql database, now how can I use the SchemaExport function in hibernate to create the tables? My application can't create the table automatically, though i have set <prop key="hbm2ddl.auto">create</prop>. This is my A...

DAO method retrieve single entry

Hello, How can I write DAO method which will return as a result only first entry from the database. For instance lets say I'm looking at Users table and I want to retrieve only the first entry, I'd declare method like: public User getFirstUser(){ //method logic } EDIT: User has primary key id if that matters at all. I apologize...

Generated queries contain schema and catalog name

I've the same problem as described here In the generated SQL Informix expects catalog:schema.table but what's actually generated is catalog.schema.table which leads to a syntax error. Setting: hibernate.default_catalog= hibernate.default_schema= had no effect. I even removed schema and catalog from the table annotation, this caus...

Why is it possible to save entity but not delete if transactional annotation is set to readonly=true with Hibernate?

Hello experts! My class is annotated with org.springframework.transaction.annotation.Transactional like this: @Transactional(readOnly = true) public class MyClass { I then have a dao class: @Override public void delete(final E entity) { getSession().delete(entity); } @Override public void save(final E entity) { getSession(...

Hibernate many-to-many mapping not saved in pivot table

I having problems saving many to many relationships to a pivot table. The way the pojos are created is unfortunately a pretty long process which spans over a couple of different threads which work on the (to this point un-saved) object until it is finally persisted. I associate the related objects to one another right after they are cre...

Where can i find the content of defaultStackHibernate interceptor stack?

I am using struts 2 and full-hibernate-plugin-for-struts2. I would like to set fileUpload interceptor <param name="allowedTypes">image/png,image/gif,image/jpeg</param> Where can i find the content of defaultStackHibernate so I can do that? ...

What does the length attribute do when set on the @Column JPA annontation?

What exactly does setting the length on a column do in JPA? @Column(name = "middle_name", nullable = false, length = 32) public String getMiddleName() { return this.middleName; } I understand that you can use the annotations to generate the database schema (DDL) based on the entity objects, but does length do any sort of check or ...

Connection reset SQLException with jetty

Hi, I've switched my webserver from tomcat to jetty and encounter a "java.sql.SQLException: Io exception: Connection reset" when back from idle time (eg. i go out for a while) :( This issue doesn't appear when i use tomcat. Does it come from jetty or i've done something wrong ? Here is my datasource config <bean id="dataSourceOracle"...

Problem on Hql query

Hi there! I have the following hql query: from Admin a where a.genericTable is null or (a.genericTable.allowInsertion = true or a.genericTable.allowInsertion is null) The problem is that the result set is excluding all entries that are comprised on filter: a.genericTable is null Does anyone knows why? Thanks! ...

Pattern for version-specific implementations of a Java class

So here's my conundrum. I am programming a tool that needs to work on old versions of our application. I have the code to the application, but can not alter any of the classes. To pull information out of our database, I have a DTO of sorts that is populated by Hibernate. It consumes a data object for version 1.0 of our app, cleverly ...

Hibernate Session flush behaviour [ and Spring @Transactional ]

I use Spring and Hibernate in a web-app, SessionFactory is injected into a DAO bean, and then this DAO is used in a Servlet through webservicecontext. DAO methods are transactional, inside one of the methods I use ... getCurrentSession().save(myObject); One servlet calls this method with an object passed. The update seems to not b...

Multivalue Mysql Inserts using HibernateTemplate

I am using Spring HibernateTemplate and need to insert hundreds of records into a mysql database every second. Not sure what is the most performant way of doing it, but I am trying to see how the multi value mysql inserts do using hibernate. String query = "insert into user(age, name, birth_date) values(24, 'Joe', '2010-05-19 14:33:14'...

Created query is not supported by my DB

I created an application using seam-gen. The created operation to search the DB ends with and exception (syntax error). The query has a where clause like this: lower(barcode0_.barcode_ean) like lower((?||'%')) limit ? Does hibnerate or seam create the where clause which my DB can't understand? Or is there a workaround for SQL stateme...