hibernate

Multiple Session Factories under Spring/Hibernate

I have been given a requirement where I need to support multiple databases in the same instance, to support multi-tenancy. Each DB has an identical schema. The user logs into a specific database by choosing from a list, and all subsequent calls will go to that DB until they log out. I want to hot swap the session factory inside a single...

Case-insensitive search using Hibernate

I'm using Hibernate for ORM of my Java app to an Oracle database (not that the database vendor matters, we may switch to another database one day), and I want to retrieve objects from the database according to user-provided strings. For example, when searching for people, if the user is looking for people who live in 'fran', I want to be...

When to use Hibernate/JPA/Toplink?

Right now I'm making an extremely simple website- about 5 pages. Question is if it's overkill and worth the time to integrate some sort of database mapping solution or if it would be better to just use plain old JNDI. I'll have maybe a dozen things I need to read/write from the database. I guess I have a basic understanding of these tech...

What is the best way to manage Time in a Java application?

So I'm using hibernate and working with an application that manages time. What is the best way to deal with times in a 24 hour clock? I do not need to worry about TimeZone issues at the beginning of this application but it would be best to ensure that this functionality is built in at the beginning. I'm using hibernate as well, just as...

Why does Hibernate seem to be designed for short lived sessions?

I know this is a subjective question, but why does Hibernate seem to be designed for short lived sessions? Generally in my apps I create DAOs to abstract my data layer, but since I can't predict how the entity objects are going to be used some of its collections are lazy loaded, or I should say fail to load once the session is closed. ...

What is the 'best' way to do distributed transactions across multiple databases using Spring and Hibernate

I have an application - more like a utility - that sits in a corner and updates two different databases periodically. It is a little standalone app that has been built with a Spring Application Context. The context has two Hibernate Session Factories configured in it, in turn using Commons DBCP data sources configured in Spring. Curr...

Workaround for Spring/Hibernate due to non-standard behaviour of UNIQUE constraint in MS SQL

There is a UNIQUE database constraint on an index which doesn't allow more than one record having identical columns. There is a piece of code, managed by Hibernate (v2.1.8), doing two DAO getHibernateTemplate().save( theObject ) calls which results two records entered into the table mentioned above. If this code is executed without ...

Hibernate saveOrUpdate - Cascade - Automatic Versioning

Hello All My question is How can I get new version number of the object after calling saveOrUpdate method? Please check following scenario class ServiceInfo{ int serviceId; Set<InfoItem> infos; int version; } class InfoItem{ int serviceId some Properties... } Mapping file for ServiceInfo <version column="VERSION...

Hibernate global filtration creteria

Is there a way to add a single criteria on a session factory(configuration) level wich will apply to all entites retreived with a Session ? We have a requirement to not delete any rows from our database but "mark" deleted entities as such so that they will not participate in any further operations. I know that we can just retrive all en...

Can I make Hibernate transparently avoid string duplication in the database?

I have a Java program that uses Hibernate and MySQL to store a lot of tracing data about the use of the Eclipse IDE. This data contains a lot of strings such as method names, directories, perspective name, etc. For example, an event object (which is then reflected in a record) can specify the source file and the current method, the use...

Customization of Hibernate sequence generation

I have one hibernate sequence, that generates all sequence-numbers in my app. When I generate the schemas from hibernate (target Oracle10), it genererates: create sequence hibernate_sequence; I would like to change the configuration of the sequence. I have to use something like: create sequence hibernate_sequence order nocache; I d...

Hibernate -- load an object based on a member object's field

How can an object be loaded via Hibernate based on a field value of a member object? For example, suppose the following classes existed, with a one-to-one relationship between bar and foo: Foo { Long id; } Bar { Long id; Foo aMember; } How could one use Hibernate Criteria to load Bar if you only had the id of Foo? The fi...

How can I serve an image to the browser using Struts 2 + Hibernate 3?

I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have an entity, User, which I have mapped to a table USERS in the DB using Hibernate. I want to have an image associated with this entity, which I plan to store as a BLOB in the DB. I also want to display the image on a webpage along with other attributes of t...

Hibernate.initialize() and second-level cache

Does anybody know if Hibernate's static initialize() method, which populates a proxy object, will attempt to hit the second-level cache before going to the database? My code seems to be behaving that way, and I can't seem to find anything in the documentation about this. The Javadoc is (as usual) sparse. Thanks! ...

Do you have a common base class for Hibernate entities?

Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with id, version and other common properties? Are there any drawbacks? Example: @MappedSuperclass() public class BaseEntity { private Long id; private Long version; ... @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long ge...

can I configure hibernate properties to connect without using an instance name to sql server 2005?

Hi, Can I configure hibernate properties to connect without using an instance name to sql server 2005? I need to force it to use localhost as the hostname and not specify the instance (same as you can do with the sql server enterprise manager). Ta! T ...

Hibernate SessionFactoryBean for multiple locations of mapping files

We have a project consisting of multiple subprojects. With each subproject we potentially have some hibernate mapping files but in the end only one actual hibernate session. Those subprojects could be combined in several ways, some depend on each other. My problem is that actually I want to have a SessionFactoryBean which would be able t...

Can anyone recommend a good reference for setting up Hibernate3 with Eclipse?

I've looked at some of the Eclipse and Hibernate tutorials and the ones for Hibernate2 are pretty good, pretty intuitive. Recently I tried to setup Hibernate3, using the Eclipse plugin, and failed to get the Hibernate tools to work, outside of physically moving the jar files from the plugins directory to my lib directory (I shouldn't ha...

What are the differences between the different saving methods in Hibernate?

Hibernate has a handful of methods that, one way or another, takes your object and puts it into the database. What are the differences between them, when to use which, and why isn't there just one intelligent method that knows when to use what? The methods that I have identified thus far are: save() update() saveOrUpdate() saveOrUpdat...

automatic query cache invalidation

hi I'm trying to understand how hibernate query cache really works. What I see now is that Hibernate does not update its second-level cache automatically when I insert new entities into the database (although I'm using only Hibernate calls). The only way I have found to make it work was to manually clean the cache after inserting new en...