hibernate

Mapping parent child relationship - composite key formed by fields of two objects

There are three object entities: GrandParent, Parent and Child GrandParent contains grandParentId Parent contains object GrandParent, parentId, some attributes, and a list of Child. Child contains childId and some attributes. There are four tables: GrandParent, Parent, Child, ParentsChildrenList GrandParent whose primary key is {gr...

OSGi vs Spring vs Struts vs EJB vs. Hibernate -- a totally newbie's question

I am not familiar with these "framework" "components" at all, but can someone give me a 101 introduction about what the relationship they are to each other? Basically, I want to know roughly about: what and what are counterparts to each other what and what are complementary technology (e.g., A as a framework can be used with B as a com...

How to enable pessimistic locking of related table in OneToOne relation

I have OneToOne relation with lazy loading. I want related entity to be loaded like with LockOption.UPGRADE option, ie with pessimistic locking. How can I do this? ...

Hibernate: specifying which column in parent entity <join/> should use

Hello. I have the following entity in my HBM file: <join table="v_price_change_current_prices" fetch="join" inverse="true"> <key column="product_color_id" /> <property name="oldMSRP" column="msrp" /> <property name="oldList" column="list" /> </join> my PRICE_CHANGE table has an ID column (primary key) and a PRODU...

java swing, spring, hibernate session transaction problem.

How do I make sure that there is only 1 sessionfactory/session/transaction when i run a test case? Currently in my test case the DataBase changes (that i make in the test case) are not visible in the application code. Here is the base class of the test. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/spring...

Modify entity with EntityListener on cascade

Hello. I have a database in which an entity (say, User) has a list of entities (say, List). As a requirement, I must have a denormalized count of the entities on the list: @Entity class User { /* ... */ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<Friendship> friends; public int friendsCou...

Hibernate one to many mapping works with a list but not a set?

Sorry to bother - perhaps this is a very simple question - but for some reason the version below fails to get parsed, whereas the version with set works fine. In fact, if I just take the set version and replace set with list I get: nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from invalid m...

Hibernate: cascade question

In hibernate, there are many information about set cascade to "all, delete" and so on, but I want to know the effect of set cascade to "none" now I have a class Parent, and it's child-class Child, class Parent{ List<Child> childs; ....} and in the file parent.hbm.xml(I omitted other content) <class name="Parent" table="parent" ...

Providing support for access to stored procedures for data transformation product

I work a data transformation product that has a GUI interface that maps one type of object to another. So it has a bunch of elements on the left that maps to elements on the right. These can be XML, Java, or database. With database the product is built on top of Hibernate, so it creates the definitions based on importing the metadata and...

Republish project error with Eclipse

Hi guys, I have a problem with eclipse and my project. When I start the server (weblogic 10.3) and publish my project, all work fine. But when I modify a class and republish the project (without restart the server), I get the following error: weblogic.application.ModuleException: at weblogic.servlet.internal.WebAppModule.start...

Hibernate: ObjectNotFoundException when object exists

Hi, I have an entity, a Group, which has User objects inside it. On creation of a User, that User is added to a Group. This is done through an API, so the flow of control is roughly: Complete web form for new user, submit Hibernate creates new user, adds user to group Website requests group and list of users Hibernate loads and return...

Problem with hibernate - persistent context

I have something like Person, and Address object(Person has an Address and other properties). I update Address or other properties in one request. And in another request I'm searching through all persons. But sometimes I can see properties modified and sometimes I cannot. Just making another request will return me either modified or u...

How to set hibernate-mapping to allow for Strings longer than 255 characters?

So I'm trying to learn by creating a blog-engine. I'm using Hibernate with MySQL. Here is my hibernate-mapping for the "Post" class: <hibernate-mapping package="com.enw.blog"> <class name="Post" table="POST"> <id name="id" column="POST_ID"> <generator class="native"/> </id> <property name="title"/> <prop...

"could not initialize a collection" + @Lob + MSSQL

When using Blob-fields in n-to-m-relations Hibernate and MSSQL are failing for some reason. SQL Error: 421, SQLState: S0001 The image data type cannot be selected as DISTINCT because it is not comparable. ... could not initialize a collection: [Dataset.documents#someID] My classes look as follows: @Entity class Dataset { @OneToMa...

How to map a composite key with Hibernate?

In this code how to generate a Java class for composite key (how to composite key in hibernate): create table Time ( levelStation int(15) not null, src varchar(100) not null, dst varchar(100) not null, distance int(15) not null, price int(15) not null, confPathID int(15) not null, ...

JPA Fetch Join Filter on List/Set

I'm having problem on JPA (Hibernate) Fetch Join : Here is my JPQL query SELECT n FROM News n LEFT JOIN FETCH n.profiles AS pr WHERE pr.id=?1 But it's not working. How can I make a query that filters on the list that is being fetched ? ...

Mapping multiple-row per item objects in Hibernate

I'm encountering somewhat of an, uh, unorthodox design and I'm not quite sure how to handle it. The table I'm trying to map looks like: TABLE example { ID INT, CATEGORY VARCHAR, PROPERTY VARCHAR, VALUE VARCHAR); A single id can have several rows (obviously, not a primary key). As an example, it could look like: # ID ...

how to configure hibernate config file for sql server

here is the config file for mysql <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property> <property name="hibernate.connection.username">root</property> <property na...

Adding a constraint to a JPA or Hibernate entity column using annotations

I want to have a column for an entity which only accepts one of an enumerated set of values. For example let's say I have a POJO/entity class "Pet" with a String column "petType". I want petType to only allow one of three values: "cat", "dog", or "gorilla". How would I go about annotating the getPetType() method in order to have a dat...

HIbernate Composite Key problem: foreign key has wrong number of columns

I am new to Hibernate and JPA, and am having difficulty setting up a composite key, as defined below: @Entity @Table(name = Entity.TABLE) @IdClass(EntityPK.class) public class MyEntity extends Entity { @CollectionOfElements @JoinTable(name="items", joinColumns = @JoinColumn(name="items")) private ...