hibernate

Why datasource is not found in JNDI after injection from jndi.properties?

This is my persistence.xml: <persistence> <persistence-unit name="MyUnit"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/abcDS</jta-data-source> </persistence-unit> </persistence> This is jndi.properties file from src/test/resources which is supposed to create a datasource during testing...

Working with part of a query at a time

I have a hibernate query which returns 10s of thousands of object results. Is it possible to cycle through chunks of the query rather than handling the entire query at once? Sample code: Query q = session.createQuery("FROM Class"); List<Class> classList = (List<Class>) q.list(); Thanks ...

What is the best way to handle a ConstraintViolationException with EJB3 and entitymanager in an SLSB

here is my code snippet: @Stateless public class mySLSB { @PersistenceContext(unitName = "db") private EntityManager myEntityManager; public void crud(MyEntity myEntity) throws MyException { myEntityManager.merge(myEntity); } } However this merge can cause a ConstraintViolationException, which does not throw MyException (which i...

hibernate inner join query on arbitrary pair of columns

Hi, I have a specific inner join that establishes a join on a PAIR of columns in one join clause. My understanding, that I want to clarify about Hibernate, is that it allows joins only if you give it control of the many-to-one and one-to-many relationships. That's unfortunate, if true, because it sure would be nice to just have hibern...

Usage of @IndexColumn results in a seq_num of 0

I would like to make use @IndexColumn to set seq number of some data the user enters. I am using Spring 2.5.6, JBoss 5.1 (JPA 1.0). For my parent class @Entity @Table(name="material") public class Material implements Serializable { . . /** * List of material attributes associated with the given material */ @OneToMany...

Strategy to fetch a subset of a collection

I have a scenario where my application has access to a session for limited time windows, during which it must fetch data from the database into memory, and then only use the in-memory data to serve requests. The data model is a simple one-to-many association such as: <class name="com.foo.Road" table="road"> <id name="oid" column="o...

Spring OpenSessionInViewFilter; why are other Sessions still being opened and closed?

Hi, I'm trying to use OpenSessionInViewFilter to avoid the infamous lazy loading errors that crop up from time to time. I've spent about a day solid on this, though, but apparently I'm doing something wrong. According to what I can tell from my log files, Spring does indeed report that it's opening a transaction from within the filter. ...

Mapping a byte[] that can grow up to 400KB on MySql

Hi, I have the following: @Entity public class ExamplePhoto { ... @Column(nullable= false) private byte[] photo; ... } I am using Hibernate and a MySql database. I tried putting a mediumblob but got a "tinyblob expected error" message. Given the fact that the photo could be of up to 400KB the tinyblob won't do the job. How can I m...

Limitation of JPA 1.0 using @IdClass with *nested* composite primary keys?

Given the following example (departments - projects): A department has the following properties (composite primary key): @Entity @IdClass(DeptId.class) public class Department { @Id @Column(name="number") private Integer number; @Id @Column(name="country") private String country; @Column(name="name") p...

Is there a way in Hibernate to obtain an entity's loaded PersistentCollection without loading the entire entity object first?

This is a puzzler! :D Is there a way to force Hibernate to load a collection for an entity without loading the entire entity first? Let m explain better. I have a Role entity annotated this way: @Entity(name="Role") @Table(name = "ROLES") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @javax.persistence.TableGenerator( name...

Using openSession() over getCurrentSession() - when and why?

This question is in relation to another question I have asked, but what are the reasons as to why you would use openSession() over getCurrentSession()? I know you would use openSession() so that you could self-manage the closing and flushing of the session, however, why would you want to do this manually? I have used openSession() when...

How to store model information in spring mvc with hibernate

Hi, I need advice how to store model in spring mvc 3 with HIbernate (example on ilustration) I have model public class Customer{ int id; String name; String surname; ArrayList<Contact> contacts; ... getters, setters } Here is class Contact public class Contact{ int id; String ...

Hibernate Session scope in JTA transactions vs Open-Session-In-View

Hi, Is it correct to say that using JTA Transactions with Hibernate contrasts using the Open-Session-In-View with regards to the session scope? From what I've been able to gather the Session scope in the JTA Transactions is a transaction (mainly based on this link) while in the Open-Session-In-View pattern the session's scope is the requ...

Why is hibernate deleting rows from join table when adding element to set mapping many-to-many?

Suposse I have two classes: class A { Set<B> bs } class B { } This mapping: <set name="bs" table="bs_tab" cascade = "save-update"> <key column="a_id /> <many-to-many column="b_id" class="B"/> </set> And join table like this: bs_tab( a_id, b_id, primary key(a_id, b_id) ) When I add some element to bs set a...

Deleting a member from a ManyToMany collection throws org.h2.jdbc.JdbcBatchUpdateException

public class Group{ @ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, mappedBy="groups") public Set<User> getUsers() { if(users == null) return new HashSet<User>(); else return users; } public void setUsers(Set<User> users) { this.users = users; } } public class User{ public void setGroups(Set<Group> groups)...

JPA QL - "winning bids of a user"

Hi, I have a simple app with User, Bid, and Auction, the relationships are clear I hope. Now I want to implement getWinningAuctionsOfuser( User u ), which would return the auctions which the given user is currently winning. I know how I would do this in SQL, but I don't have much experience with JP-QL. What's the best approach? Curr...

Best practice in ColdFusion ORM

A question of ColdFusion ORM We are using ColdFusion 9 for the past 6 months and while we've used some of the new features, ORM is something we've avoided because we usually work on the same very large website. Over the years we've used Apache OBJ but then we moved back to CF and used our own DAO objects generated from tables to handle ...