hibernate

Hibernate logging with log4j

I have the following code and I am still unable to get Hibernate to write SQL queries to log file. It perfectly writes them to the Eclipse console. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" > <log4j:configuration> <appender name="file" class="org.apache.log4j.RollingFileAppender"> <param ...

Hibernate - How to persist a new item in a Collection without loading the entire Collection

Hello - I ahve asked this on the Hibernate forums but no one seems to have been able to provide an answer so I am trying here! Thanks chaps! I have a collection in my model that contains a set of 'previous versions' of my root domain object. The previous versions are therefore 'immutable' and we will never want to update them, and only ...

Map entity using query in Hibernate

consider table sales (id, seller_id, amount, date) and here is a view that is generated from sales using query SELECT seller_id, SUM(amount) FROM sales GROUP BY seller_id total_sales (seller_id, amount) I want to make an entity for total sales but without the view on the sql side. This entity will be constructed from a query. The ...

What is the missing parameter in connection pooling?

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="c3p0.max_size">100</property> <property name="c3p0.idleConnectionTestPeriod">300</property> <property name="c3p0.acquire_increment">1</property> <property name="c3p0.idle_test_period">100</property> <!-...

Hibernate subquery

I have a problem in creating subqueries with Hibernate. Unfortunately the Subqueries class is almost entirely undocumented, so I have absolutely no clue how to convert the following SQL into a Hibernate Criteria: SELECT id FROM car_parts WHERE car_id IN ( SELECT id FROM cars WHERE owner_id = 123 ) I was hoping the following would 'jus...

Hibernate Mapping Package

I'm using Hibernate Annotations. In all my model classes I annotate like this: @Entity @Table public class SomeModelClass { // } My hibernate.cfg.xml is <hibernate-configuration> <session-factory> <!-- some properties --> <mapping package="com.fooPackage" /> <mapping class="com.fooPackage.SomeModelClass" /> ...

Hibernate Search Annotations not Inherited

I am indexing a class whose superclass has the following annotations: @Indexed @Entity @Inheritance(strategy = InheritanceType.JOINED) The same @Inheritance annotation is on the subclass. The annotations of the superclass are all on methods. The field I want indexed on the superclass is ignored: @Field(index=Index.UN_TOKENIZED,st...

Reusable Hibernate EntityManager (J2SE)

Hello, we are developing a J2SE application and we are using Hibernate for our persistence layer. For our database access I created a singleton class that has all the necessary methods to obtain and persist objects from the database. But once I created the second method for obtaining objects I immediately realized that I have a smelly co...

Mapping hibernate components to a separate table

Is it possible to configure Hibernate to store a component class in a separate table? Take the following example: <class name="test.ClassA"> <property name="propA"/> <component name="componentProp" class="test.ClassB"> <property name="propB"/> </component> </class> This maps to a table called MyClass with two columns p...

How to map in XML List<Entity> field with hibernate.

I googled all day and I cant find one good example how to map this kind of objects: class Parent{ private Integer parentId; private String parentName; private List<Child> childs; // ....... getters and setters ............ } class Child{ private Integer childId; private String childName; private Parent par...

How to use the Hibernate optimistic locking version property on the front end?

Optimistic locking using the version attribute for an entity works fine and is easy to implement: <version property="VERSION" type="int" column="EX_VERSION" /> The entity has a property of the following type: private int VERSION; public int getVERSION() { return VERSION; } public void setVERSION(int VERSION) { this.VERSION = VERSION;...

MySQL Licensing in a Commercial Web Application using Hibernate

I am evaluating the prospect of developing a commercial java web application using Hibernate as the ORM framework. This application would be installed on a customer's server and would be used by a small number of users. Also I do not want to release my source code since the application is mission critical and it would potentially jeopa...

Best way to manage transactions

I've the JBoss and Hibernate based system. And I need to process two long operations. Operations can be probably longer than transaction's timeout. It operations are persists many-many entities, in two different transactions. And if something goes wrong, during this operations, I should rollback all changes of the transactions. What's ...

Native Stored Proc v/s Hibernate

I am a newbie in Hibernate. I am working on a cloud service data access layer. Currently we are using Hibernate for OR mapping and as data access layer using Hibernate annotations. But lately i have been asked to implement Hibernate/Data Access layer in such a way that my stored procedures be in HQL and we can change our DB at a short ...

Mapping a list in hibernate by ordering instead of an index-field

This works: <hibernate-mapping> <class name="Train" table="Trains"> <id column="id" name="id" type="java.lang.String" length="4"> <generator class="assigned" /> </id> <set name="trips" cascade="all"> <key column="trainId"/> <one-to-many class="Trip"/> </set> <...

NHibernate one-to-many relationship lazy loading when already loaded

I have a tree where every node is a Resource class: public abstract class Resource { public virtual Guid Id { get; set; } public virtual Resource Parent { get; set; } public virtual IList<Resource> ChildResources { get; set; } } as you can see this class is abstract and there are many different derived cl...

How do I decide the number of connections required in connection pooling?

I am using hibernate 3.2.2 in my application. For connection pooling, we are using c3p0 0.9.1. I am using Generic DAO Pattern and Open Session in View pattern to do database operation. We are working on new website of existing website. Right now, the no of visits is half million page visit in existing application. I am confused with t...

Selecting MappedSuperclass from the database (Hibernate)

Problem I have a @MappedSuperclass called Data as the parent of every Entity in my database. It contains common attributes like Id etc. I then have an entity that extends Data which is also a @MappedSuperclass due to common functionality of its subclasses. The mapping in my database is correct. Here is an example of my hierarchy @Map...

SQL Server JDBC: unable to create new native thread

We are using Microsoft's sqljdbc driver 1.2 in combination with Hibernate under Windows. Occasionally we are getting an OutOfMemoryError from the JDBC driver although plenty of memory is still available in the JVM heap. Here's a stack trace of the exception we are getting: java.lang.OutOfMemoryError: unable to create new native thread ...

About hibernate NamedNativeQuery

Hello, I am a newbie in hibernate, I am using @javax.persistence.NamedNativeQuery to resolve my stored proc calls from hibernate to mysql but i am getting errors. Please help: My persistent class is: @Entity @javax.persistence.NamedNativeQuery(name = "SampleNameQuery", query = "call spS_NamedQuery(?,?)", resultClass = NamedQuery....