hibernate

Set Hibernate session's flush mode in Spring

Hi! I am writing integration tests and in one test method I'd like to write some data to DB and then read it. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) @TransactionConfiguration() @Transactional public class SimpleIntegrationTest { @Resource private DummyDA...

Are many-many relationships to be avoided and if so, what is the alternative?

I was left a comment that many-many associations are to be avoided, but I cannot find the original comment/user who left me this info. So I'm asking the community, are many-many associations to be avoided, if so why, and what is the alternative? example: A restaurant offers many types of burgers which can be dressed with many different...

Hibernate @CollectionOfElements Annotation for internationalisation

Hi Does anyone know of a good example (on the net) of how to use the @collectrionOfElements annotations in Hibernate. I have existing model objects and I need to internationalize a few fields on each of them ie: Name, Description . . . Does this mean I do not have to change/add new tables and model objects as Hibernate will know how to...

Config Spring for works with hibernate and entities mapped by annotations

Hi all, im using hibernate and i maps my entities with annotations (so no xml files). I finally decided to try spring framework but I encountered some problems to make it work. All tutorials i found are very dispersive and most of them use xml file to map an entity... Can you help me to correctly write a xml config file for spring+hibe...

Grails quartz->thread

This is my Trigger that calls a matchService... class TestJob { def matchService static triggers = { cron name: 'firstThread', cronExpression: "0 0/1 12-13 ? * THU" } def group = "threadGroup" def execute() { matchService.playMatch() println "run thread: " + String.format('%tH:%<tM:%<tS.%<tL',System.current...

managing hibernate sessions

I am trying to debug a web app that is having some performance issues. i turned on hibernate logging and i am seeing a lot of this: 2010-10-28 10:58:00,423 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5276786198212608 2010-10-28 10:58:01,390 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 5...

How does one write a Hibernate "UserType" where the type has a collection in it?

I have a Validity object which contains two dates, start and end. I have a UserType that I've written for this so that I can simplify the hibernate mappings for the several entities that have one. That works fine. Now I want to add a set of weekdays to Validity. The only solution I can figure out is to change each entity to treat Val...

@ManyToMany in an abstract MappedSuperclass

Hi. I'm having the following design for my hibernate project: @MappedSuperclass public abstract class User { private List<Profil> profile; @ManyToMany (targetEntity=Profil.class) public List<Profil> getProfile(){ return profile; } public void setProfile(List<Profil> profile) { this.profile = prof...

Spring+hibernate and @Transactionl annotation, how it works?

Hi guys, what is the difference between use @Transactional over a method and not use it? I write some simple test but seem to be no difference. I want to learn how to manage transaction using spring and annotation. thank all. ...

Save new object with Hibernate using supplied ID

I want to save some Objects to database with predefined IDs using Hibernate. Is it possible to do it using save method of Hibernate session? I know there are following workarounds: 1) execute SQL script with necessary insert statements: insert into MyObj(id,name) values (100,'aaa'), (101,'bbb'); 2) use SQL query in Hibernate: pub...

Retrieving a child object after a commit on an entity object

Lets say I retrieve an entity object that looks like this: @Entity public class Mother { ... @OneToMany(mappedBy = "mother", targetEntity = Child.class, fetch = FetchType.LAZY) public List<Child> getChildren() { return children; } } When retrieving the above object, I commit the t...

Possible to upgrade jboss 5.1 jpa1 to jpa 2

Is it possible to upgrade Hibernate/JPA that is shipped with JBoss 5.1 to use JPA 2.0? I am interested in making use of the OrderColumn. I am unable to upgrade JBoss to the latest version - 6 ...

Committing a database change in isolation to the main transaction

Let's say I have the following code: public void doSomething() { // begin transaction // do stuff 1 ... // update a row which must be committed now ... // do stuff 2 ... // commit transaction } I've kept the large amount of work on the database in the one method to simplify the pseudo code. However...

How to force Hibernate to add quotes to generated SQL statements?

Hi! Hibernate is generating invalid SQL for a particular criteria query. I can manually fix the query by adding single quotes to the value being used in the WHERE clause. To fix it, I changed the query from: where (role0_.ROLE_ID=2L ) to: where (role0_.ROLE_ID=`2L` ) How to force hibernate to add single quotes (in mysql it is si...

Best practice to generate a JPA dynamic, typed query?

Hello there, i'm trying to convert a 'TableController'-Class we used (without ORM) to generate dynamic SQL (actually the order column and direction is appended to the SQL). Think of this 'TableController' as a class that have a function to return a list of Entities of a given class (known at runtime), in a given order (String column/pro...

What is the correct way to initialize collection of an entity (POJO) in Spring-Hibernate project?

I have a POJO class, say Foo, which has a Set of other entity instances, say bars. Also there are standart misc classes for such project: service and dao for both Foo and Bar. I want BarService to get the Set of Bar instances associated with some Foo. Now I have the following code, wich I believe is conceptually bad. public class Foo...

jax-ws web-service tier to the hibernate-based data provider

A data provider (java, hibernate) has an API for accessing instances of JPA-annotated classes. A web-service (jax-ws) is exposing the API to the network clients. A bit of a problem I'm thinking to solve is that a client of the data provider cannot be easily reconfigured to either use the provider directly or over the web-service. The rea...

Hibernate auto-increment property

I know you can auto-increment an id by mapping; <id column="user_id" name="id" > <generator class="increment"/> </id> But is it also possible increment a property, what I tried so far didn't work; <property column="numeric_value" name="nr" > <generator class="increment"/> </property> ...

In Extjs While updating in Grid if Session Timeout how to redirect to login page ?

Hi, How to identify the sessiontime out issue while updating the value in the grid and redirect to login page.. my application (java spring hibernate with extjs) i.e.. i am updating the extjs grid record and while submitting the changes, if the session is expired i need to identify that particular exception and redirect to the login ...

How to cascade delete an entry without cascading into ManyToMany relations

Hello, I have a piece of code that 'updates' an entry in the database by first cascade deleting it, and then replacing it with a new object, because I had a lot of problems trying to update it normally. This hack worked fine, until I started using some ManyToMany relations. This is the relation that is giving problems: @ManyToMany(casca...