hibernate

How do you map a collection of base type objects in a derived type of the same inheritance tree?

Background The object model is such that: A 'Component' is a primitive, it cannot be made up of smaller parts. A 'Part' is a composite. It can be made up of 'Components', other 'Parts', or any combination of the two. I have modeled this by having a Part inherit from Component and then having the Part have a collection of Component o...

Cannot delete or update a parent row - JPA with Hibernate

I have a database in which all of the tables have been generated by Java JPA/Hibernate code. I need to update several tables in my database in a fashion similar to this, UPDATE Department SET id=100000 WHERE id=0; Unfortunately this results in the error ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constr...

Hibernate is not updating record - Wicket

Hi. I'm working on a web application with Wicket, Spring and Hibernate and I've come across a problem with updating records. I have verified that the saveOrUpdate method is invoked, and that the data in the domain object has changed. The SQL-output does however not display that any changes to the database has been made (UPDATE in exampl...

Hibernate, assigning multiple columns as primary key

Hi, I am having below database schema. Table:items item_id int(11) autoincrement not null item_name varchar(22) not null version_start_date datetime not null version_end_date datetime The primary key for above table is (item_id,version_start_date). The semantics of version_start_date and version_end_date is to keep track of any chang...

@OneToMany does not insert foriegn key in Hibernate+JPA

Hi folks, I am facing some strange issue, I have a user table(use class) and a country table(country class). An user may have N number of countries. Hence, I have added a List of countries in the user class with the getter and setter method. In the table I have made the country_id as foreign key in user table. And, I have a @OneToMany o...

query results are not found in cache

Env: JBoss 5.1, ehcache 2.1.0, hibernate 3.3.x, seam 2.2.0 ehcache.xml (2.1.0 version) contains the following lines, but my query results are not found in cache. Am I supposed to set a cache region for each of the queries which are fired. What am I missing here? <!-- Cache configuration --> <cache name="org.hibernate.cache.UpdateTimest...

hibernate map java Long to MySQL BIGINT error

i have a table with id field type BIGINT in MySQL in hibernate object, i use java Long type for this field but when run program, it throw exception: Expected: class java.lang.Long, got class java.lang.Integer how to map MySQL BINGINT datatype in hibernate ? ...

Hibernate: Why does a change of bag lead to strange ADDs and DELETEs in the database?

Hello, I have an n:m-association between the two classes User and Role, implemented as a bag with lazy="extra". The association is stored an an association table sind a user can have many roles and a role can be associated with many users. Now when I add a new role to a user, hibernate emmits sql code that first removes all entries in ...

Multilevel transaction in spring and hibernate

I am facing problem while executing the database transactions in spring and hibernate. I want to execute the these transaction through multi level transaction. Example as given below There are there transactions, written in hibernate methods using spring. Each Transaction in each methods (Total three) 1) Delete the data from T1 w...

Hibernate: Shallow copying of ManyToMany associations without initialization of target entities

There are two entities: @Entity class A { @ManyToMany List<B> bs; } @Entity class B {} I now want to duplicate (clone) an instance of class A. Is there any way with Hibernate to make a shallow copy of the persistent collection bs without having to completely initialize all Bs? In SQL it would be quite easy because you would just ...

Single persistence unit for a modular application (JPA)

I want to create a modular(plugin-like) application that uses JPA as its persistence abstraction, and this application should be extensible by third parties. The catch is that I want this application and its plugins to be easily portable to other databases/JPA providers, so the third party vendors can't know anything about the used JPA p...

Hibernate with Annotations and MySQL: Creation Date

Hey folks, I try to save the date of creation of my entity. I have found that approach. I tried to implement it but the date doesn't reach my db-table. import java.io.Serializable; import java.util.Date; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.PrePersist; @Entity public class Project im...

Log files not generated with Hibernate and slf4j

In my application I'm using Hibernate, Apache Commons Logging and Log4J. But my log files are not getting generated. Is these because Hibernate uses slf4j? In my classpath I have the following jars. hibernate-3.2.7.ga.jar hibernate-annotations-3.4.0.GA.jar hibernate-commons-annotations-3.3.0.ga.jar hibernate-core-3.3.2.GA.jar hibernat...

Hibernate with MySQL : Auto-Generate Id : Equivalent of Sequence (Oracle) in MySQL

As far as i Understand, when 'Native' class is used for auto id generation in Oracle, a single hibernate sequence is created, from where all the IDs are supplied to whichever table needed. But i dont see this happen with MySQL. Instead, id's for each table start with 1. Please correct me if am wrong. Also, if i want the same tu happe...

Hibernate and Event based Interaction

Hi, For my persistence framework I am using Hibernate. What I would like to do is the following: Whenever a new row in inserted (or value of a column changed) in a specific DB table, I would like Hibernate to call a specific procedure? How do I handle this in Hibernate? Thanks, Neel ...

Hibernate: Strategy/pattern for object and entity identity mapping using composite keys?

What is a general collision-free Java best practice to generate hash codes for any-type (atomic types) multi-column primary keys? I thought about it for a few hours and came to the conclusion, that a string concatenated by all primary key columns would be the only reliable way to do so. Then calling Java's hashCode method on that concat...

Hibernate confusion. What are the differences between ga, GA and Final Releases? Compatibility? Repository?

Can anyone please explain: 1. The difference between ga, GA and Final Hibernate releases? 2. Should I use the maven repository or the jboss nexus repository? 3. Why does the latest compatibility matrix (http://community.jboss.org/wiki/HibernateCompatibilityMatrix) not list anything higher than 3.2.6GA? I'm using the following versions...

Netbeans + derby + hibernate

I'm following http://netbeans.org/kb/docs/java/hibernate-java-se.html tute to setup hibernate with derby in netbeans IDE. Netbeans fails to create hibernate.reveng.xml with error : "Cannot establish database connection with selected Hibernate Configuration file. Please verify the database connection details in hibernate.cfg.xml" My hib...

Hibernate mapping for one-to-one

Hi, I have two classes binded mapped with Hibernate and I can't figure out the configuration to map a Drug entry to my PrescribedDrug class. public class PrescribedDrug implements Serializable { protected int prescribedDrugId; private int drugId; protected String sig; protected int quantity; protected int refillNumb...

jpa hibernate composite foreign key mapping

I am having trouble setting up jpa mappings for some entities. I have a parent entity defined like the following. @Entity @Table(name="EIF_INSTANCE_HDR") public class InstanceEntity implements Serializable{ private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator="eif_inst_gen") @SequenceGenerator(name="eif_inst...