I want to log all changes in my database for auditing purposes, using a table called AuditEvent that stores the modified row ID (primary key), table name, column name, previous value, new value, date of change (timestamp), operation type (insert / update / delete) and the name of the user who did the changes.
I'm using SQL Server 2005,...
Hi guys, when I trying to update the object RFQ , Hibernate tends to update its child collection BQMaster and trying to set and update the identifier of BQMaster which normally it should not be allowed.
The postgre log file:
*2009-05-22 11:16:53 ERROR: duplicate key violates unique constraint "bq_masters_pkey"*
*2009-05-22 11:16:53 STAT...
Having a hibernate mapping a legacy database I want to use EnumTypes to map certain columns that contain string constants with whitespace to some Enum class.
The mapping:
@Entity
@Table(name = "OPERATOR")
public class Operator {
@Id
@Column(name = "ID")
private Long id;
...
@Enumerated(EnumType.STRING)
@Colu...
[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct to (or even is) the answer.]
Hi, my question relates to these software: Hibernate3+Annotation, Spring MVC, MySQL and in this example also Spring Security.
I was wondering, why collections, which are automatically associated by Hibernate contain null v...
I have a simple many-to-many mapping:
@Entity
@Table(name="ITEM")
public static class Item
{
@Id
@GeneratedValue
long id;
@Column
String name;
@ManyToMany(cascade={ CascadeType.ALL })
Set<Category> categories = new HashSet<Category> ();
}
@Entity
@Table(name="CATEGORY")
public static class Category
{
@Id...
I'm just getting started with Hibernate, and all the examples I'm seeing so far look pretty much like the tutorial in the Hibernate documentation:
package org.hibernate.tutorial.domain;
import java.util.Date;
public class Event {
private Long id;
private String title;
private Date date;
public Event() {}
/* Acces...
I have two related entities, say
@Entity
public class Book {
@ManyToOne
Shelf shelf;
}
@Entity
public class Shelf {
@OneToMany(mappedBy="shelf")
Set<Book> books;
}
If I fetch an empty shelf (no books), create and persist a new book to the shelf and then fetch that shelf again, its books collection is empty. When I run...
I have a situation in which I need to re-attach detached objects to a hibernate session, although an object of the same identity MAY already exist in the session, which will cause errors.
Right now, I can do one of two things.
1.) getHibernateTemplate().update( obj )
This works if and only if an object doesn't already exist in the hibe...
I'm currently using Spring+Hibernate+MySQL for a project I'm working on. I realized that a have quite a few tables which never change. They are static, no insert or updates can ever occur on these tables, and so can be considered immutable. All accesses to these tables are via lazy loading (can be made eager) of entity collections and...
Hibernate has no support for "delete-orphan" cascading of one-to-one or many-to-one relationships. I recently discovered this, and it's giving me a serious headache. I have a couple classes in my model that were designed such that the child has no real world meaning outside of the parent. I only have one DAO for the parent, and not a ...
MySQL supports an "INSERT ... ON DUPLICATE KEY UPDATE ..." syntax that allows you to "blindly" insert into the database, and fall back to updating the existing record if one exists.
This is helpful when you want quick transaction isolation and the values you want to update to depend on values already in the database.
As a contrived exa...
how can we get distinct result by using criteria in hibernate.
...
Hi Gurus,
I am wondering how to write the model, hbm.xml for table
Company
-------
id(PK)
name
address
typeid(fk)
Type
----
id(PK)
type
class Company(){
int id;
String name;
String address;
Type type;
}
class Type(){
int id;
String type;
}
(with get/set methods)
How to write the hbm?
I am using the hibernate 3.x.
...
How can I make this work in unit tests using Hibernate 3.3.1ga and HSQLDB:
@Entity
@Table(name="CATEGORY", schema="TEST")
public static class Category { ... }
The problem is that Hibernate expects the schema to exist. The second problem is that Hibernate issues the CREATE TABLE TEST.CATEGORY before any of my code runs (this happens de...
com.something.SuperClass:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
private static final long serialVersionUID = -695503064509648117L;
long confirmationCode;
@Id
@GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
p...
I am dealing with legacy database. And I am writing unit test using pojos & hibernate & HSQLDB. And I am getting the following error:
17:09:03,946 ERROR SchemaExport:349 - Attempt to define a second primary key in statement
Let's say I have Post and Tag entities (and of course their tables posts and tags). And there is another table to...
I'm using JPA and I am using second-level cache for all the reference entities.
Everything's working well, I can get the entities from second-level cache is they were already been selected before.
Now, I have two applications, they both use the same database (so they both use the same table, values, etc).
1.The read-only application ju...
Given the following:
@Entity
public class Parent implements Serializable {
@Id
private Long id;
// mapped ManyToOne below...
private List<Child> children = new ArrayList<Child>();
...
}
Is it a bad practice to have Parent.equals() and Parent.hashCode() use only id? I understand that Child.equals() and Child.hashCode() shou...
I have an object with a field that can be a number of object types. This object is encoded in a single table with a discriminator column for the field's subtypes. Each of these subtypes have their fields mapped to a column in the parent objects table. I cannot seem to model this in hibernate. The code bellow will return null for getSubfi...
I have multiple services which call on my database service, which uses Hibernate, and I would like the remote services to be able to create a query and then pass that to be processes. Ideally I would like to pass a Criteria Object but it looks like it needs a Session which they won't have access to. Is there a process similar to the Crit...