hibernate

How do I delete orphan entities using hibernate and JPA on a many-to-many relationship?

I want to delete orphan entities using hibernate and JPA on a many-to-many relationship but all that I found was this atibute the attribute. org.hibernate.annotations.CascadeType.DELETE_ORPHAN ( i.e. @Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN) ), which works only for one-to-many relationships. I want to know if ...

How to enable Hibernate Interceptor when i have my Hibernate Transaction managed by Spring ???

If i have a @OneToMany relationship with @Cascade(CascadeType.SAVE_UPDATE) as follows public class One { private Integer id; private List<Many> manyList = new ArrayList<Many>(); @Id @GeneratedValue public Integer getId() { return this.id; } @OneToMany @JoinColumn(name="ONE_ID", updateable=fals...

TestConnectionOnCheckin c3p0 Configuration Property in Hibernate/Spring Framework

I would like to set the testConnectionOnCheckin property for c3p0. However I am having trouble doing so because the c3p0 datasource is created on my behalf within a hibernate entity-manager bean. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitM...

How do I rebuild hibernate3.jar from the 3.5.2 distribution?

I made some changes to the hibernate source and need to rebuild hibernate3.jar. I tried "mvn deploy" but I get a 401 (trying to upload to the jboss repository, which I don't want to do). I followed the instructions here: http://community.jboss.org/wiki/HibernateRelease35wMaven . I'm basically unpacking hibernate-3.5.2.GA.tar.gz, enter...

Why is an oracle sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?

All my entities use this type of @Id @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYENTITY_SEQ") @SequenceGenerator(name = "MYENTITY_SEQ", sequenceName = "MYENTITY_SEQ") @Column(name = "MYENTITY", nullable = false) private Long id; Or @Id @Column(name = "MYENTITY") I find that an oracle sequence named hibern...

Joining tables 3 level deep using Alias in Hibernate Criteria

4 tables. table 1 >> mapped to table 2 mapped to table 3 mapped to table 4. I want to get a column data from table 4, in my search criteria for table 1 object. Is it possible using Alias. Is there any way using any API of Hibernate Criteria to get table 4 data in table 1 object using search criteria. ...

Hibernate, select by id or unique column

I am using hibernate for Java, and I want to be able to select users by id or by name from the database. Nice thing about Hibernate is that it caches the result by id, but I seem to be unable to make it cache by name. static Session openSession = Factory.openSession(); public static User GetUser(int Id) { return (User) openSessio...

What cache concurrency strategy should be used for @ManyToOne fields

What cache concurrency strategy should be used for @ManyToOne fields for a particular entity class. Would it make sense to use READ_ONLY instead of READ_WRITE, since these fields usually don't change after entity creation @ManyToOne(fetch = FetchType.LAZY) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) ... private User user; ...

Any good Codeset/Code Value libraries and/or patterns?

I'm being forced to use code values for on-going projects and can't seem to find a good, eloquent solution besides brute force lookups for every code value. Are there any good libraries anyone can suggest, or any good design patterns to retrieve/swap code values? FWIW, I'm in a Spring/Hibernate shop. I had been using a @Codified annot...

Persist subclass as superclass using Hibernate

I have a subclass and a superclass. However, only the fields of the superclass are needed to be persist. session.saveOrUpdate((Superclass) subclass); If I do the above, I will get the following exception. org.hibernate.MappingException: Unknown entity: test.Superclass at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(Se...

hibernate for dynamic table creation

i AM A HIBERNATE BEGINNER ,Since i need to create dynamic tables with dynamic fields in them i chose to use hibernate . As far as my understanding , creating tables requires a class with the fields defined in the class . How do i generate the classes dynamically based on the table with the required fields ? ...

Modifying annotation attribute value at runtime in java

Hi folks: some methods in our model pojos have been annotated like this: @Column(name="cli_clipping_id", updatable=false, columnDefinition = "varchar(" + ModelUtils.ID_LENGTH + ") COLLATE utf8_bin") columnDefinition attribute is database vendor dependant, so when trying to drop schema in HSQLDB using Hibernate it fails: [ERROR] 16 j...

Restrict the class of an association in a Hibernate Criteria query

I have an object, 'Response' that has a property called 'submitter'. Submitters can be one of several different classes including Student, Teacher, etc... I would like to be able to execute a criteria query where I select only responses submitted by teachers - so this means putting a class restriction on an associated entity. Any ideas...

Is it possible to override Hibernate's 'like' operator in HQL ?

I'm wondering if the following is feasible in Hibernate ; when writing an HQL query, you can say things like select foo from Foo where foo.barString like "%baz%" This works assuming that class Foo has a String attribute called barString. Now, assume that Foo as a bar attribute of type Bar, but that Bar has a well-known, canonical S...

Hibernate mapping to manage bidirectional relationship using intermediate table

I have an object hierarchy that is as follows. Party > inherited by > Organization and Person Organization > inherited by > Customer, Vendor Person > inherited by > Contact In the database I have the following tables Party, Customer, Vendor, Contact. All of them have a corresponding row in Party table. Contact belongs to either Vendor...

Tomcat/Hibernate Problem "SEVERE: Error listenerStart"

I downloaded working example of hibernate (with maven) and installed it on my tomcat, it worked. Then I created a new web project in MyEclipse, added hibernate support and moved all source files (no jar) to this new project and fixed package/paths wherever was necessary. My servlets are responding correctly but when I add "Listener" in w...

Hibernate Implemetation Problem

I am developing a project at java fresher level. I had to implement database interaction using hibernate. At the first stage, I started using HQL query language. But, later I come to know about Crieteria through my previous questions. But, still after learning crieteria, I am not getting what are the steps I should follow to fill and fet...

How to map XMLType with JPA/Hibernate

How to persist XMLType column via JPA/Hibernate? As per oracle documentation, there are two ways in declaring storage clause for XMLType. They are, LOB and Object-Relational. I dont want to go with LOB. I have schema and register into database. I have not have example on how to design my Entity for XMLType. Does any one know please share...

Persisting Serializable Objects in Hibernate

I am attempting to persist objects that contain some large Serializable types. I want Hibernate to automatically generate my DDL (using Hibernate annotations). For the most part, this works, but the default database column type used by Hibernate when persisting these types is tinyblob. Unfortunately, this causes crashes when attempting t...

Hibernate and Child Objects (add versus clear)

Lets say I have domain model with Automobile and Wheels. Wheels is a List of Wheels Wheels has a many-to-one relationship to Automobile. If I get an object back from Hibernate and it has 4 wheels. I take that object remove the 4 wheels and add 4. And then Save. If I ask Hibernate for the object again and it returns an auto with 8 wheels...