hibernate

How I can disable the second-level cache of some certain entities in Hibernate without changing annotations

Hello, I'm using Hibernate second level cache in my application, for certain business reason I can't change the entity annotation any more. In my project, apart from changing the Database from Hibernate, there exist also other native SQL that do not go through Hibernate. Therefore, the Hibernate second-level cache data could be stale a...

hibernate auto join conditions

Hibernate persistence class: @Entity public class A { @OneToMany(mappedBy = "a") private Set<B> bSet = new HashSet<B>(); @Basic private boolean DELETED; } Class B also have a DELETED property. How can we process DELETED property during join automatically, for select only not deleted entities. May be with hel...

indexing data in Hibernate Search

I just start integrate Hibernate Search with my hibernate application. The data is indexed by using Hibernate Session everytime i start the server. FullTextSession fullTextSession = Search.getFullTextSession(session); Transaction tx = fullTextSession.beginTransaction(); List books = session.createQuery("from Book as book").list(); for...

Modifying property names in JPA queries

I'm using a convention of prefixing field names with an underscore. When I generate annotate entity classes with such fields I am stuck to using the underscore-prefixed property names in queries. I want to avoid that, and be able to do: @Entity public class Container { private String _value; } // in a lookup method executeQuery("f...

Hibernate second-level cache ehcache.xml, the cache setting for entities can't be read to HIbernate

To make it clear and easy, I have two projects: 1. An Entity project where there are all the entity classes in this project. 2. An project that contains a main() function to run the application, My ehcache.xml is placed in the class path of this project. My problem is: I can change the defaultCache element of ehcache.xml and I can see c...

JPA/Hibernate Parent-Child - DAOs for both Parent and Child or just Parent?

For a parent-child entity relationship, when (and why) would you use a DAO interface for only the parent and when would you make also make DAO for the children? To me, it makes sense to only make a DAO for the parent if the Children MUST belong to a parent and should not exist as orphans. So if I wanted to delete a Child, I would modif...

How to encapsulate database access?

I am developing a transactional application in .NET and would like to get some input on how to properly encapsulate database access so that: I don't have connection strings all over the place Multiple calls to the same stored procedure from different functions or WORSE, multiple stored procedures that are different by a single column ...

Hibernate - Selecting across multiple joins with collections

I'm having trouble getting a hibernate select to return a correctly populated object graph, when the select contains joins across many collections. Eg: String sql = "select distinct changeset " + "from Changeset changeset " + "join fetch changeset.changeEntries as changeEntry " + "join fetch changeEntry.repositoryEntity as re...

Multilingual fields in DB tables

I have an application that needs to support a multilingual interface, five languages to be exact. For the main part of the interface the standard ResourceBundle approach can be used to handle this. However, the database contains numerous tables whose elements contain human readable names, descriptions, abstracts etc. It needs to be pos...

Is ORM (Linq, Hibernate...) really that useful?

I have been playing with some LINQ ORM (LINQ directly to SQL) and I have to admit I like its expressive powers . For small utility-like apps, It also works quite fast: dropping a SQL server on some surface and you're set to linq away. For larger apps however, the DAL never was that big of an issue to me to setup, nor maintain, and more...

How do I map a nested collection, Map<Key,List<Values>>, with hibernate JPA annotations?

I have a class I am not sure how to annotate properly. My goal for Holder::data: List should maintain order not by comparator but by the natural ordering of the elements in the array. (Which can be an ndx column if that is helpful.) Holder will have the only reference to data, so Cascade all is probably applicable as well. I am al...

How to resolve this Exception : Data source rejected establishment of connection, message from server: "Too many connections"

I am using Hibernate 3 +Mysql 5.1 and after 98 insertion i am getting this Exception : com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections" My hibernate.cfg.xml file is : com.mysql.jdbc.Driver jdbc:mysql://localhos...

How is a blob column annotated in Hibernate?

How is a blob column annotated in Hibernate? So far I have a class that has: @Column( name = "FILEIMAGE" ) private byte[ ] fileimage ; // public byte[ ] getFileimage ( ) { return this.fileimage ; } public void setFilename ( String filename ) { this.filename = filename ; } ...

disable property/collection loading with hibernate

does anyone know how to prevent hibernate from loading a collection or many-to-one assocation? i have a use case where i need to load an object, but the calling program can determine whether certain properties are loaded or not. the same goes for part of a collections: certain rows have to be fetched, others not. domain classes: publi...

What is a good strategy for migrating a hibernate class from a sequence based integer primary key to a GUID primary key while retaining the old keys for backward compatiblity?

We have an extensive class hierarchy (using the joined-subclass model) where the base class has a Long primary key generated from a sequence in the DB. We are working on transitioning to a GUID primary key, but wish to retain the old primary key (both in old and newly created content) for legacy apps. While the implementation seems f...

Recommended logger for use with Java, Hibernate and Spring

My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are my logger choices and what would you recommend. Ideally the configuration would be simple (one config file for Hibernate, Spring and my code). ...

Automap a property who's type is Interface

I have the following class class MCustomer : DomanEntity { public MCustomer( ) { } public virtual iCustomerEntity CustomerDetials {get;set;} public virtual SolicitationPreferences SolicitationPreferences { get; set; } } public interface iCustomerEntity { Contact ...

Hibernate/JPA - annotating bean methods vs fields

I have a simple question about usage of Hibernate. I keep seeing people using JPA annotations in one of two ways by annotating the fields of a class and also by annotating the get method on the corresponding beans. My question is as follows: Is there a difference between annotating fields and bean methods with JPA annoations such as @I...

Comparing entities while unit testing with Hibernate

I am running JUnit tests using in memory HSQLDB. Let's say I have a method that inserts some values to the DB and I am checking if the method inserted the values correctly. Note that order of the insertion is not important. @Test public void should_insert_correctly() { MyEntity[] expectedEntities = new MyEntity[2]; // init expec...

How to config QueryCache in ehcache.xml

From my sql log file, I think the QueryCache's physical properties are configured by the element: <defaultCache maxElementsInMemory="0" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false" memoryStoreEvicti...