hibernate

Maven Java Source Code Generation for Hibernate

Hi, I´m busy converting an existing project from an Ant build to one using Maven. Part of this build includes using the hibernate hbm2java tool to convert a collection of .hbm.xml files into Java. Here's a snippet of the Ant script used to do this: <target name="dbcodegen" depends="cleangen" description="Generate Java source from ...

Hibernate - ManyToOne - Save - org.hibernate.TransientObjectException:

While I try to save top level entity (using JPA), do I need to get the ManyToOne mapped entity freshly from database and set it or cannot I just set Id (of manyToOne mapped entity and save top level entity? When do not get fresh entity it throws: org.hibernate.TransientObjectException: Table structures we are using: DEPARTMENT(DEPARTME...

Search result was due to field in Hibernate Search

I have a Hibernate search that searches from many a field of an object. Is it possible to know which of the fields matched the results for each result object? ...

Can I access the c3P0 connection pool properties programmatically?

Hi, I am worried that the properties I have set for my C3P0 connection pool are not being used correctly. Is there a way I can access the values that are set while the application is running and print them out: Println("Minimum connections"+connectionNumers.minimum); Thanks ...

How can I remove an item from a Hashmap in Hibernate ?

Hello, I try to delete an item from a hash map with hibernate. Here is my config on the collection: @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @Where(clause = "charactType='charact'") @MapKey(name = "shortcut") @Cascade(org.hibernate.annotations....

Hibernate HQL query by using like operator

Hi, Seu the following mapping @Entity public class User { private Integer id; @Id; private Integer getId() { return this.id; } } Notice id is an Integer. Now i need this HQL query by using like operator Query query = sessionFactory.getCurrentSession().createQuery("from User u where u.id like :userId"); A...

Multiple database with Spring+Hibernate+JPA

Hi everybody! I'm trying to configure Spring+Hibernate+JPA for work with two databases (MySQL and MSSQL) my datasource-context.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/a...

Handle Transaction on differents EARs

Hello, what is the best practice to handle multiple EARs and the same transaction, as far as we know we need to apply XA concepts in order transaction works correctly. but apparently in currents project that we've been working on, this is not strictly necessary for creates and updates; however if we try to retrieve any collection from an...

Hibernate cascade delete not working when removing element of recreated bean

Supposing these are my parent and my child objects: Parent: @Entity @Table( name = "import_table" ) public class ImportTable { @Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN } ) @OneToMany( mappedBy = "table", fetch = FetchType.EAGER ) public List<ImportTableColumn> getColumns() { re...

Hibernate Configuration Xml

Hi. I am developing a java web application using hibernate as ORM. Is it possible to merge Hibernate.cfg.xml with the applicaion-config.xml? ...

unique constraint check based on a parameter in the parent table

Table User has (userId, scoreType, ...) @Table(name = "User", uniqueConstraints = @UniqueConstraint(columnNames = userId)) -- scoreType could be either points or percentage Table UserScore (id, userId, points, percentage) I would like to provide the flexibility to store either points or percentage based on user.scoreType. So if ...

Set Table character-set/collation using Hibernate Dialect ?

I use Hibernate MySQLInnoDB Dialect to generate DDL's. hibernate.cfg.xml : <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> How can I configure the character-set/Collation to 'utf8_general_ci' for the generated table? ...

How do you turn on a hibernate filter for a particular entity by default?

Good day, I currently have an Entity that has a where clause set on it. I want to put that where clause on a filter and have that turned-on by default (so that I won't break any existing functionalities). I want to turn it into a filter so that I can disable it because I have a use case wherein I need it disabled. How can I do that in...

How can you call custom database functions with Hibernate?

If I were to define some function in the database (perhaps Postgres, or any other database): create or replace function isValidCookie(ckie); I would call it from SQL as: select * from cookietable c where isValidCookie(c.cookie); How can I call a custom function such as this from Hibernate? ...

Hibernate and padding on CHAR primary key column in Oracle

I'm having a little trouble using Hibernate with a char(6) column in Oracle. Here's the structure of the table: CREATE TABLE ACCEPTANCE ( USER_ID char(6) PRIMARY KEY NOT NULL, ACCEPT_DATE date ); For records whose user id has less than 6 characters, I can select them without padding the user id when running queries using SQuirre...

Using Hibernate/JPA without relationships and avoiding multiple DB calls

It seems to me that when you use relationships in Hibernate/JPA that using relationships like OneToMany can have a performance boost on reads because only one database call would need to be run to get a parent entity and all children entities. I want to avoid using relationships and just map foreign key columns as normal columns due to ...

What is a natural identifier?

When reading through the Hibernate documentation I keep seeing references to the concept of a "natural identifier". Does this just mean the id an entity has due to the nature of the data it holds? IE: A user's name+password+age+something are its identity? ...

Hibernate collection handling basics

Hi all, I"m new to Hibernate. I have 3 tables: Companies, Profiles and Sites. The relation is - one company has many Profiles and Sites (one-to-many). <hibernate-mapping> <class name="com.bla.dataobject.CompanyData" table="companies"> <id name="companyId" column="company_id"> <generator class="increment"/> </id> <property name="...

Hibernate mapping collection by column

Hi there, lets take this example <class name="Product"> <id name="serialNumber" column="productSerialNumber"/> <property name="category" column="category" /> <set name="categories"> <key column="productSerialNumber_FK" not-null="true"/> <one-to-many class="Part"/> </set> The collection mapping always maps with the id from t...

Hibernate is not able to load a JAR file if my directory name contains space!

Hello, I have an application that is based on Swing, Spring 2.5.2, Hibernate 3.3.1. If my application is run from a directory that contains a space character, for example D:\hudson\jobs\FooBar - Fast Build, then I get this error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFacto...