hibernate

Using JPA mapped by not primary key field?

I am having troubles getting this working and I wonder if what I am doing simply does not make sense? public class Application { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="id") private long id; .... } @MappedSuperclass public abstract class Sample { @Id @GeneratedValue(strategy = Generatio...

hibernate query.list() method is returning empty list instead of null value

When there are no rows, both query.list() and criteria.list() are returning empty list instead of a null value. What is the reason behind this? ...

JPA/Hibernate can't create Entity called Order

Hi, I'm using Hibernate/JPA and have an @Entity object called Order, pointing at a MySQL database using Hibernate's dynamic table generation i.e. generate tables at runtime for entities. When Hibernate creates the tables, it creates tables for all of my entities except the Order entity. If I rename the Order entity to something else e.g...

how to query specific fields in hibernate criteria

I need to fetch only specific feilds instead of all fields. All my tables has audit feilds(4) . i want that to be ommitted on the selection. how to do that from mapping. is there any other way?. Criteria criteria = session.createCriteria(Property.class, "property") .createAlias("property.propertyType", "type").createAlia...

How does multi child query by example in hibernate work?

I'm using query by example and I have an object which has two child objects. The problem I have is I want to make a query which has limitations for both child tables and I cant work out how you do it. When I do this: List results = session.createCriteria(Cat.class)      .add( Example.create(cat) )          .createCriteria("owner")      ...

JPA - getting distinct value from one column

I have an entity that has few fields. One of them is city name. Now I want to get list of all distinct cities from that table. How can I archive that. I tried using DISTINCT keyword, but it doesn't work. I'm using Hibernate as JPA provider but I would like to get it in pure JPA Query. ...

JPA+Hibernate(J2SE) @OneToMany - Millions of records slows adding a new object down.

Hello, I'm using JPA+Hibernate with a PostGre SQL database in a J2SE project. I have 2 entities A and B. A has a @OneToMany relationship to B. In my domain model A might reference millions of B's. When I add a new object to the collection it takes minutes to complete. @OneToMany(cascade=CascadeType.PERSIST) Collection<B> foo = new Arra...

How expensive is committing a hibernate transaction?

Hi, I have a the following use case where I'm receiving a message via JMS regarding an entity, via a unique property of it (not PK) and it requires me to update the state of the entity: HibernateUtil.beginSession(); HibernateUtil.beginTransaction(); try{ Entity entity = dao.getEntityByUniqueProperty(propertyValue); if (ent...

Hibernate tuning for high rate of inserts and selects per second

Hello, We have a data acquisition application with two primary modules interfacing with DB (via Hibernate) - one for writing the collected data into DB and one for reading/presenting the collected data from DB. Average rate of inserts is 150-200 per second, average rate of selects is 50-80 per second. Performance requirements for both...

JPA-2.0 Simple Select-Where question

I am stuck with a problem concerning JPA-2.0 queries with relationships. How would it be possible to select any Dataset with at least one Event with type = B? @Entity class Dataset { @OneToMany(fetch = FetchType.LAZY, mappedBy = "dataset") public List<Event> events; } @Entity class Event { @ManyToOne @JoinColumn pub...

How to use the entity query framework to model the following query

We have a query which needs to check if a certain integer field points is not null and if appointmentDate is before current date? How do I write the restrictions expression for the above scenario? @Entity public class User { ... Integer points; Date appointmentDate; ... } ...

Sharing Hibernate on multiple Tomcat instances

Hi, I have 4 web applications, that have a common reference to an Hibernate implementation but that run on different Tomcat instances. And so, for example, a connection pool configured in Hibernate with a min size of 3 (with c3p0), will result in 12 connection open (3 for each instance) when all the projects are running . I'd like to "...

Java Hibernate and servlets with Adobe Flex + Model View Controller Pattern ?

Hi Guys, I am preparing a document for a project. The project's backend is developed in Java, frontend is adobe flex. I am not sure about the correct way of describe the project in Model-View-Controller way. For Model layer: Using Hibernate Java beans to implement all the business logic and persistence? For View Layer: Using Adobe ...

Looking for a tutorial using MyEclipse 8.6, Spring, Hibernate

I just installed MyEclipse and have not located a tutorial using MyEclipse with Spring 3 and Hibernate. I would appreciate it if anyone could refer me to such a tutorial. Thanks. ...

org.hibernate.hql.ast.QuerySyntaxException: Product is not mapped [from Product]

My infuriating problem of the day is this: I'm trying to use Hibernate to access a database. After a number of false starts, I gave up on my specific project and elected to use the sample database and wizards that shipped with Netbeans 6.9. I fired up Netbeans, started the sample Derby database, and followed the instructions in this tu...

Control sort order of Hibernate EnumType.STRING properties

Currently, my project uses @Enumerated(EnumType.ORDINAL), so when I sort by this column, it is ordering based on the order in the enum, which works fine. But I need to add some additional values to the enum, which need to be inserted at different locations in the list of enum values and can't be just added to the bottom to maintain the c...

OnDeleteAction cascade fails with constraint violation error

Hibernate 3.3.x @Entity public class User { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OnDelete(action = OnDeleteAction.CASCADE) @Cascade(value = DELETE_ORPHAN) @OrderBy private List<Phone> phones= new ArrayList<Phone>(0); ... } Cascade delete is not enabled if you have some ...

when we load hibernate using spring we have to just call methods for CRUD function

when we load hibernate using spring we have to just call methods for CRUD function but what exactly Spring hibernate do to fire query ...

@SequenceGenerator on class annotated with @MappedSuperclass

Hello! I have following structure of my entities: @MappedSuperclass public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator") private Long id; } @MappedSuperclass @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @SequenceGenerator(name = "seqGenerator", sequenceName...

PostLoad method is not being called on an Id class

I have an entity class and another class is Identity class of this entity. I have written @javax.persistence.PostLoad annotation in Id class to put some default value on one of the column. But I found out that it is not being called at all. Is it that ID classes should not have this annotation? ...