hibernate

EJB3/JPA entity with an aggregated attribute

Hi all, I wanted to know if there is a way to get in a One2Many relationship a field of the One side that is an aggregate of the Many side. Let's take the following example: @Entity public class A { @Id private Long id; @OneToMany (mappedBy="parentA") private Collection<B> allBs; // Here I don't know how to Map the latest B by d...

hibernate always deletes all data from a table on its own

Hi i am developing a spring mvc app thats using hibernate to connect to a mysql database that stores files. I have two methods. one that adds all files from a specific file path of my choosing and another method that invokes a query to return me a list of the files stored from mysql. The issue is this. When i execute the first method o...

Criteria Many-to-Many Hibernate

@Entity public class Person implements Serializable { private int id; ........... private Set<Languages> languages = new HashSet<Languages>(); ............... @ManyToMany @JoinTable(name = "link_person_languages") public Set<Languages> getLanguages() { return languages; } } @Entity public...

Use SQL Information to Populate Schema Documentation and Code Comments Using Hibernate Tools?

I have set up Hibernate Tools from within Eclipse to autogenerate classes based on an existing DB. For each of the tables I have documented them and each of their columns within SQL Server. Is there a way to use that documentation information to comment the generated classes and to populate the schema entity documentation? I see that ...

Select using hibernate

Hello, I saw few examples over internet of Hibernate using transaction.commit() for select statements. Below is the example code. public static List<?> list(Class<?> className,int start,int limit,SearchFilter[] searchFilter){ Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = null; ...

Multiple composite ids with relations or single field PKs

I've been dealing with composite id's and asked a few questions and I was recommended to replace my composite PK's with a single id column, and to control integrity with indexes... All of this related to the fact that mapping composite id's isn't that simple... On the other side, some people encourage the usage of composite id's that a...

Which Classes are Cached in second level cache in hibernate

Is there a way for me to find out which Classes (i.e instance of which different types ) are cached in hibernate second level cache. ...

Hibernate delete objects on cascade

Hi, I'm sligthly confused as to how the cascade="delete" works. I defined the mapping in the following way in the City mapping file: <set inverse="true" name="client" cascade="delete"> <key> <column name="id_name"/> </key> <one-to-many class="model.Client"/> </set> The class Client has a foreign key to a class City. So w...

Persist enum with business value with hibernate annotations.

I have enum ClientType{INTERNAL,ADMIN}, i am able to persist enum with hibernate annotations. but inserted value is INTERNAL,ADMIN. How can i define my own vlaue. I want table to contain "I" for INTERNAL. How can i do this hibernate annotations. ...

Is there a way to look into L2 hibernate cache?

Hello everybody. I have a task to attach Oracle Coherence (it is cache software) in my project. One way of using it is Level2 Hibernate cache. I want to see when hibernate takes results from L2 cache. How can i do that? Both ways will be good: listener of some sort, if possible, or direct access to Cache object. Thanks in advance. ...

Hibernate/Spring: Error loading lazy collection in a @Transactional

I though I understood lazy/eager loading, but obviously I don't: I have a service that is marked @Transactional, yet when I try to manipulate the list I get (accessing its objects), I get "org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: tld.myproduct.data.entities.CategoryType.translatableTex...

query for collection property using projections in Hibernate?

Hi Say I have an entity that looks like this: class Person{ long id; List<String> names; } the names collection is a property (not a relation) Is there a way to query for the names using projections? first attempt: sessionFactory.getCurrentSession() .createCriteria(Person.class) .setProjection(Projections.projectionList() ...

If I persist a class using hibernate, how do I ensure that the values of some fields are merged while others are created?

Suppose I have a class 'Cheese' with fields type and purchaseDate, such that: public class Cheese{ CheeseType cheeseType; String purchaseDate; public setPurchaseDate(String value){ purchaseDate=value; } public Class CheeseType{ String type; public setType(String value){ type=value; ...

Database changes done by one instance of an application is not being picked up another instance using Hibernate.

I have an application which can read/write changes to a database table. Another instance of the same application should be able to see the updated values in the database. i am using hibernate for this purpose. If I have 2 instances of the application running, and if i make changes to the db from one instance for the first time, the updat...

JDBC Driver class not found in Hibernate program

I am making a simple mapping program in hibernate. I am facing an error: JDBC Driver class not found: com.mysql.jdbc.Driver java.lang.ClassNotFoundException: com.mysql.jdbc.Driver It gives an error on this line: Session session = HibernateUtil.getSessionFactory().openSession(); hibernate.cfg.xml is correct. In the same configratio...

Complicated query with hibernate criteria.

Hello, I want to get QuestionVersion with max versionNumber for each Question. Next I need to check status of those versions and get QuestionVersionContents associated with versions with correct status value. Following statement seems to work but I need It as criteria or at least HQL: select c.content, c.language_id, qv.status, qv.ver...

Hibernate type used to map java.lang.Double

Hello, I am using "double" in Hibernate .hbm.xml files, and when I generate classes with Hibernate Tool I get class property which has primitive type double. I want this property to be java wrapper type Double. How can I achieve this? If I change this manually in my classes, is it going to give any issues to hibernate? Thanks ...

How do i use HibernateTemplate.findByNamedParam() ??

HI, i am trying to use the above spring hibernate temnplate method do a simple query based on a specific ID from the database but the problem is that the query doesnt replace the ":" character from the sql string below into the value contained in "id". i thought that this method replaces ":" with the given parameter i set in the method ...

object references an unsaved transient instance

hi, I get this hibernate error(in the title), when I turn off the cascading(Cascade.ALL) and start to manually em.persist() the lower-in-the-hierarchy entities. So this is not possible at all? I'm sure that the entities are persistent before, they are even in the database, but I get this error. How to fix it? EDIT: java.lang.IllegalStat...

Why are user input dates losing a day? (But not when run locally?)

First, I hope this is the right place for this question. Because I believe this to be a server configuration problem, I wasn't sure if this should go on serverfault. So we have a spring-mvc webapp running on Tomcat servers and connected to an Oracle database. On one of these pages is a form for the user to fill out where they can enter ...