hibernate

Mapping Siblings in NHibernate

I've been trying to build a SiteMapNode styled object with NHibernate mappings. The goal is to mimic the ASP.NET SiteMapNode object so that a custom provider can be built using NHibernate for a dynamic backend. The issue I'm running into is the way the tree nature of a site map. The ASP.NET object has a next and previous sibling obj...

How to simulate NVL in HQL

I tried this: from Table where (:par1 is null or col1 = :par1) but it happens that from Table where :par1 is null always returns all the rows of the table, even if the :par1 is not null. while select * from table where col1 = 'asdf' does not return any row. I can't use native grammars because my application is supposed to run...

How do I externalize named queries in a Hibernate annotations app?

Is there a way to externalize HQL named queries to an external file. I have too many named queries and using @NamedQueries/@NamedQuery at the head of my entities classes is hurting. Is there a way to externalize to several files? ...

ConcurrentModificationException and a HashMap

I am persisting objects using JPA. The Main object has an owning One-Many relationship with another object. The other object is stored in a HashMap. What sort of synchronization would fix this problem? It seems to happen at completely random times and is very unpredictable. Here is the exception I get: Exception in thread "pool-1-t...

Using a NamedQuery with a composite class

I have the following class defined in my mapping XML file: <class name="com.data.StateRefData" table="STATE_REF"> <composite-id name="primaryKey" class="com.data.StateRefPkData"> <key-property name="countryCode"> <column name="COUNTRY_CODE" /> </key-property> <key-property name="state"> ...

Hibernate: Identifier

When using Hibernate: Must I identify an id or composite id for each entity, What about if I want to use table without any primary key and without composite key ... Thanx in advance ...

Enum tables in Hibernate/NHibernate

We are using NHibernate, and one of the common patterns we have for storing enum-like information is to define separate tables for the enum, and just make a reference to the ID in the main entity/table that uses the enum. A simple example: Message ------- ID (bigint PK) MessageTypeID (bigint FK) Body (varchar) MessageType ----------- ...

How can multiple webapps in the same tomcat instance share database connection pool?

Having in mind that each webapp has its own separate database (but all databases are in the same database server). The scenario is that I have a multi-tenant saas application - I deploy the same application for each customer. Each customer works on a database that is called db_cid, where cid is the customer id, i.e. a a unique customer ...

Legacy mapping with hibernate

For my current project I have to map a legacy database using hibernate, but I'm running into some problems. The database is setup using one 'entity' table, which contains common properties for all domain objects. Properties include (among others) creation date, owner (user), and a primary key which is subsequently used in the tables for ...

Gridview like display for hibernate objects in Java?

Essentially what I am looking for is a good way to build a quick database interface. In my (limited) experience with ASP.net I've used a Gridview control for this task. However for this project I am going to be using Java. Can anyone recommend a good way to set up a Gridview like control (with editable and sortable rows) in a Java web f...

Hibernate: load a field from a query , but don't insert it to the table

Hey I have a bean with a certain field f1 that should not be mapped into the table , but sometime I do want to load it from some queries (not the table itself) Can it be done? How? I've tried declaring it @Transient , but then it doesn't read it from the query , even when I declare <return-property name="f1" column="f1"/> Thanks! ...

Hibernate HQL: two levels of joins

I am new to HQL and have the following table relationships: Term has many Definitions Definition has many DefinitionProducts DefinitionProducts has one Product I want to get the list of Terms that have at least one Definition that has at least one DefinitionProduct that has a specific Product This is my best attempt (in Grails): Te...

Hibernate: Is there a way to programatically create new tables that resemble an existing one?

I have a web app that have many tables (each represents a POJO). I wrote mapping files for each class and then use Hibernate's SchemaExport to generate the tables in my database. Now I want to create 2 additional tables for each existing table that was created: User permission table - stores user permissions on the POJO specific to ea...

Hibernate: Difference between session.get and session.load

From the API, I could see it has something to do with proxy. But I couldn't find a lot of information on proxy and do not understand the difference between calling session.get and session.load. Could someone please explain or direct me to a reference page? Thank you!! ...

In hibernate statistics whats the difference between load and fetch

Im mainly looking at the EntityStatics (http://www.hibernate.org/hib_docs/v3/api/org/hibernate/stat/EntityStatistics.html). I can see a lot of fetch, loads and updates and i cant find anywhere that says what the difference between them are. ...

Is there a java implementation of the ActiveRecord pattern that is built on top of Hibernate, similar to Castle Windsor?

I am looking for a Java implementationation of the ActiveRecord pattern which is built on top of Hibernate. In .Net there is a open source project Castle Windsor ActiveRecord which implements the ActiveRecord pattern on top of NHibernate. I'm looking for something like this, except sitting on top of the NHiberate persistence frameowork...

Ant: How do I fix a WrappedRuntimeException when using <xslt> task?

I tried to use the xslt task in Ant to modify a Hibernate mapping file (*.hbm.xml) using XSLT. However I kept on getting an com.sun.org.apache.xml.internal.utils.WrappedRuntimeException. If I take out the !DOCTYPE declaration in the source xml file, the following target runs without any error. Could someone please tell me what I'm doing...

Can I map an EnumSet to a series of boolean columns automatically using Hibernate Annotations?

I have an EnumSet that I thought it would be good to map into a series of boolean columns. This will make it easy to inspect using SQL tools and also resilient to changes to the available enum values. However, I don't really want to hand-write all the getters and setters for this. Does anyone have a clever solution using some kind of ...

Hibernate: How to map a *.hbm.xml file in a different folder?

I have some *.hbm.xml files that are placed in the same folder at the hibernate.cfg.xml file. Now, I want to map some other *.hbm.xml files that are in a subfolder of this folder. How could I do it? Thanks! here's part of my hibernate.cfg.xml: <hibernate-configuration> <session-factory name="MySessionFactory"> <...

Concurrency when using GORM in Grails

Let's say I have a counter function which updates a counter using raw SQL: public void updateCounter() { executeSql("UPDATE counter SET count_value = count_value + 1 WHERE id = 1;"); } The database would make sure that two concurrent calls to the counter are handled as expected - that all calls would update the counter with one i...