hibernate

Map a list of strings with JPA/Hibernate annotations

I want to do something like this: @Entity public class Bar { @Id @GeneratedValue long id; List<String> Foos } and have the Foos persist in a table like this: foo_bars ( bar_id int, foo varchar(64) ); UPDATE: I know how to map other entities, but it's overkill in many cases. It looks like what I'm s...

Get Hibernate Entity instance from id column in SQLQuery result

I have (non-Hibernated) database tables that contain ids for Hibernate entities. I can query them (using createSQLQuery), which gives me the ids, from which I can then load the entities. I'd like to do that in one step, and I think I can do that with addEntity, but I am not sure how exactly. (Hibernate's documentation web site is down. ...

Hibernate with relations

Hello everybody... I have a relational DB, contains tables and all kinds of relations(1>n, n>1, 1>1 and n>n).. Let's take one of these tables which is "Department" table, this table is the most complicated table in my DB, because it has relations with most of the table in the DB. The XML mapping file "Department.hbm.xml" looks like: ...

How can I create a hibernate collection that will be re-read every time I request it?

I have an entity that has a state table associated with it. The state table is managed by another process, and contains a list of objects that my business logic must process. I would like to get a new snapshot of the state table each time I reload the entity. How can I ensure that no part of Hibernate or its support libraries ever cac...

Need help with design structure and looking up EntityManager and UserTransaction in helper's helper

Hi there, I am basically a newbie whose starting work on a new webapp. The webapp is mostly your basic CRUD operations. For this, I have decided to use JPA with Hibernate as the Persistence provider and will be developing on Apache Derby for development and testing purposes. I am using GlassFish v2 as the App Server to deploy my EJB3 be...

Splitting Hibernate Entity among 2 Tables

I have a simple Class Hierarchy that I am trying to get to work with Hibernate/JPA. Basically what I want is for the MovementData to be in its own Table with a FK to the integer id of the Main Vehicle Table in the Database. Am I doing something wrong? How else can I accomplish something similar? I am pretty sure I am following the JPA...

Do you think of the database or objects first when building applications?

When you think about building an application, say for the web, and it uses a relational database, do you think about the database first and then putting you app as a front end or do you think of your program and objects and how a database can store those. I'm trying to change the way I think but it hasn't clicked (I'm not sure I'm even ...

Hibernate doesn't save and doesn't throw exceptions !?!

Hi, I'm stuck with this already for some weeks and I don't have the faintest idea what's going wrong. I'm quite desparate as I've wasted so much time already I use the data model described below (MySQL). I have created the hbm.xml and java classes by reverse engeneering (Eclipse/JBoss Tools) (see example below). When I try to save tw...

Dialect for SQL2005

Hi all, I am new to Hibernate. We are migrating one of our existing web application which uses Hibernate 3 and SQL 2000 server to SQL 2005 server. Can I get help about which version of Hibernate to use with SQL 2005 as I could not find any dialect for SQL 2005 in Hibernate 3.0.5? Thanks in advance. ...

Using hibernate hbm2ddl.auto=update : How can I alter column not to require value anymore?

I had a property that used to be not-null="true". Values aren't necessary for that field anymore so I changed it to not-null="false" but the table does not get updated in the database. Adding new properties doesn't give any problems. Is it possible for hbm2ddl.auto=update to change the the table automatically to remove the not-null="tr...

make Eclipse equals() / hashCode() use getters

Is it possible to make the default Eclipse "Generate hashCode() and equals()" use getters instead of field references? - ie. can I get at the template that it uses? I'm using Hibernate, and Proxied Objects are only LazyLoaded when getters are used and not from field references. It's an annoyance to be constantly changing it. The obviou...

JPA EntityManger preforming a database insert on merge?

I am using JPA with Hibernate underneath, and I am having trouble getting merge to work, but before I describe the problems I am encountering with JPA, let me lay out what I am trying to accomplish, just in case my problems stems from my approach. I have data from on system that I need to place into another system. To do this I am read...

How to log user operations in a web application?

Hi. The environment of my application: web-based, Spring MVC+Security, Hibernate, MySQL(InnoDB) I am working on a small database application operated from a web interface. There are specific and known users that handle the stored data. Now I need to keep track of every create/update/delete action a user executes on the database and pro...

Hibernate: "Field 'id' doesn't have a default value"

Hi, all. I'm facing what I think is a simple problem with Hibernate, but can't get over it (Hibernate forums being unreachable certainly doesn't help). I have a simple class I'd like to persist, but keep getting: SEVERE: Field 'id' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: cou...

Hibernate Complex type save

i need to persist an object whose one of the properties is an enum. This whole structure have to be saved in a single table. The enum defines the possible genders public enum Gender { MALE,FEMALE } The main class is public Person { String name; Gender gender; } If this Person class has to be persisted in a single table, how should...

Spring + JPA (Hibernate) on Glassfish --> ClassVisitor problem

I'm trying to write a simple web app with Spring 2.5 (core + MVC) and JPA (using Hibernate for the persistence mechanism). Every time I deploy, I'm getting a "Class not found exception" that points to ClassVisitor. This is a known version problem with the asm library. In a stand-alone app, I can make sure that the proper asm version i...

Select constant in hibernate?

In SQL I can perform the following select 10000 as num Can I do something similar in hql. I know it sounds like a strange request. I do not want to use the Criteria api, and I don't have access to the query, I can only pass an hql string to a method that will then perform the query for me. ...

MyEclipse+Hibernate does not order property sets by ID?

I use Hibernate with Java. I have two tables which are associated with foreign keys. Table: country Fields: ID, Name POJO class name : Country POJO class properties: id, name, cities Table: city Fields: ID, Name, CountryID POJO class name : Country Then I use "hibernate reverse engineering" of MyEclipse. It creates DAOs, abstracts ...

Is hibernates caching mechanism implemented so that it can be (if configured properly) a short term 'replacement' for the db behind it?

Meaning that I would like to load a set of objects and have the cache used exclusively when different queries that operate on that data object or set of objects instead of letting queries 'leak back' to the database. If the answer is yes, which cache provider offers this or do all of them and what configuration parameters do i need to be...

hibernate deletion

i have a course object. The course object has a set of tutorials and a set of applications. When i delete a course objects i want the assocated set of tutorials and applications to get deleted. My course.hbm is as follows and my application.hbm contains ...