hibernate

Hibernate: How to delete child records instead of setting foreign key to null

I have a User and a set of Authorities in a one-to-many relationship: User.hbm.xml: <set name="authorities" table="authorities" cascade="all-delete-orphan"> <key column="user_id" /> <one-to-many class="com.ebisent.domain.Authority" /> </set> When I delete a user, I want to delete the authorities as well, but what is happening...

collection-type argument in Hibernate?

Hello, I was thinking if I could set the list elements type in hibernate mapping files. So far I found this collection-type attribute like here: <list name="privileges" cascade="all" table="user_privilege" collection-type=""> , but I am not sure if I put my list element full class name if Hibernate will generate my domain classes pr...

How to inject a spring's service bean into a JPA Entity ?

My problem is very similar to this one : Injecting fields via Spring into entities loaded by Hibernate The difference is that , I am using JPA2 entities , not hibernate . While the underlayer is still hibernate (3.5.5). My spring version is 3.0.4. What's the corresponding eventListeners in JPA's world ? Sample code from the original ...

Logging Entity changes in Java Web Application

Hi, We have a requirement on our project, where we need to maintain a sort of history of changes that are made to certain Entities in the Application. The the Application is a Java Web App based on Struts, Spring and Hibernate. What sort of approaches have been used in this case ? Triggers on the respective tables is one idea but the...

Hibernate: Update onetomany list

Hi guys, I have got a onetomany relation in Hibernate: @Entity public class Project @OneToMany(cascade = CascadeType.ALL) @OrderColumn(name = "project_index") List<Application> applications; @Entity public class Application Now, I tried to update an application directly: session.merge(application); The result is...

Is there an annotation to define a multi column index in jpa2

Hibernate provides a mechanism to define multi column indexes via the Table. Is there a way to specify this is an ORM agnostic fashion via JPA or JPA2 (e.g. using the javax.persistence.* APIs) ...

Obtaining session in Hibernate Listener with Spring Integration

When Hibernate is used with Spring, making the DAOs extend HibernateDaoSupport provides the getHibernateTemplate() which is used to obtain the session. When using a Hibernate Event Listener, I am extending the SaveOrUpdateEventListener and so cannot use the getHibernateTemplate() method to obtain Session. Is there any way to obtain the...

problem in posting data from client side to server side in OnetoOneMapping

In Spring MVC when I submit data from my form then the exception occurs as given below. The situation is like I have Entity class and I have taken another Entity in it as part of relationship. when I send data to display it is working properly but when I post data after editing exception occurs. I have tried initbinding as well but does...

Hibernate Event Listeners Patterns

Hi, For a Java Web Application (Struts / Spring / Hibernate), Hibernate Event Listeners are new feature for Audit logging. When there is need to capture some extra information such as the User who updated an Entity, details of what entity attributes changed compared to preview entity attributes etc, are there best practice patterns tha...

Some basic JPA+Hibernate Questions?

Hi, I have some basic questions: 1) How many xml files involved in JPA+Hibernate combination, if JPA annotations were used? i am having just persistence.xml. 2) Is hibernate.cfg.xml needed, if i use JPA annotaions. Because, i didnt added it till now. 3) Shall anyone give me the list of basic JAR file names, in case of using JPA 2.0 & ...

Hibernate/Oracle seqhilo generator

Hi, I'm trying to configure a seqhilo generator for a Hibernate application on Oracle. <id name="idTest" type="int"> <column name="ID_TEST" precision="6" scale="0" /> <generator class="seqhilo"> <param name="sequence">S_TEST</param> <param name="max_lo">1000</param> </generator> </id> I created...

Hibernate custom identifier generattion

Hi, I am now using hibernate as ORM technique in my application. I have a table called Order and I want the hibernate to generates the ID for each instance when inserting new order into the table. Quite unusual, the desired auto-generated id should be something like this: first time: jialhe001 and then jialhe002 .... jialhe003, jialhe0...

When is innodb_lock_wait_timeout ignored ?

Related to my other questions, I'm having a weird case of the classic deadlock exception: Caused by: java.sql.BatchUpdateException: Deadlock found when trying to get lock; try restarting transaction. blablalbla... The code is identified and indeed, it's possible to get a deadlock. The thing is that I'm getting the exception immediatly. ...

TransientObjectException while saving the details to the database.

"Table 1" can have multiple instances of "Table 2". "Table 2" is one to one mapped with "Table A". But the instance for "Table A" is created by "Table B". "Table 1" need not always have an entry of "Table 2". Table 2 has two columns say tb1 and tbA. tb1 references to primary key of "Table 1" and tbA to that of "Table A". If the data f...

Hibernate DateCreated, DateModified columns from DB not VM(App)

Using Hibernate 3.5.1 and MSSQL 2008 Hi trying to implement the typical DateCreated and DateModified columns. The issue I have is that the time must be set from the DB not the application. For DateCreated I can set the property to generated = always and set a default constraint (yes that reads right damn MS) on MS SQL 2008 to a default...

How to define an non-JTA datasource for JPA-Hibernate? org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource:

Hi all, I am trying to change my web-app's JDBC code to JPA using Hibernate as provider. I am using Eclipse IDE. In that i have defined a MySQL data source. I added it in the persistence.xml. But, I am getting the below error. 6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find da...

What does this error mean and how can I fix it?

I'm using this DAO class which was generated by Hibernate Tools: /** * Home object for domain model class Empleados. * @see com.hibernate.Empleados * @author Hibernate Tools */ public class EmpleadosHome { private static final Log log = LogFactory.getLog(EmpleadosHome.class); private final SessionFactory sessionFactory = g...

java.lang.NoClassDefFoundError: org/hibernate/mapping/MappedSuperclass

Hi all, Again, I am new to JPA & Hibernation. I am trying to use JPA technology in my web app. With the help of stackoverflow users, I have cleared many errors. With that experience and Confidence, I thought that I can do further myself. But, the current error is something different. I am not able to find it in google itself. Its somet...

Map two entities using a shared foreign key column in hibernate

I have four entities to map together, "Association", "Account", "Transaction" and "TransactionEvent". The id of Association is a simple integer id. Account and Transaction each have embedded id's consisting of a mapping to an Association and a number. TransactionEvent should have an embedded id consisting of one Account and one Associat...

Partition a large Hibernate model to manage schema dependencies

We are considering splitting our hibernate tables into packages or domains (invoicing, sales, ..etc), primarily for dependency management issues. It doesn't break neatly of course, so we aren't sure how to handle relationships that cross domains. It would be nice to have a new entity annotation for this, but meanwhile one idea is to ma...