hibernate

ORA-00942: table or view does not exist : How do I find which table or view it is talking about

Hi Guys, We're running a java/hibernate app going against ORACLE 10g in TESTING. Once in a while, we're seeing this error(ORA-00942: table or view does not exist). Is there a way to find out which table/view(s) ORACLE is talking about ? I know that I can add extra levels of logging in hibernate which will show all the SQL that it execu...

Hibernate: Criteria vs. HQL

What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when HQL? What do you prefer in which use cases? Or is it just a matter of taste? ...

Hibernate @ManyToMany mapping with composite keys

Hello ! I'm trying to map a ManyToMany relationships between 2 tables, both having composite primary keys LSFOCTB which primary key is composed of : LSFOC_CODSOC,LSFOC_CODLSC,LSFOC_CODFOC LSFORTB which primary key is composed of : LSFOR_CODSOC,LSFOR_CODLSC,LSFOC_CODFOR The table in charge of the ManyToMany relationship is : LSFCFTB,...

Hibernate Delete Cascade

I Have one entity [Project] that contains a collection of other entities [Questions]. I have mapped the relation with a cascade attribute of "all-delete-orphan". In my DB the relation is mapped with a project_id (FK) field on the questions table. this field cannot be null since I don't want a Question without a Project. When I do sess...

Hibernate Union alternatives

What alternatives do I have to implement a union query using hibernate? I know hibernate does not support union queries at the moment, right now the only way I see to make a union is to use a view table. The other option is to use plain jdbc, but this way I would loose all my example/criteria queries goodies, as well as the hibernate ma...

Best practice to realize a long-term history-mode for a O/RM system(Hibernate)?

I have mapped several java classes like Customer, Assessment, Rating, ... to a database with Hibernate. Now i am thinking about a history-mode for all changes to the persistent data. The application is a web application. In case of deleting (or editing) data another user should have the possibility to see the changes and undo it. Since ...

HQLfind instances of a class that have all of a given list of keys in its composite-map-key

<classname="Source" table="source"> <component name="map" access="field"> <map name="parameters" access="field" table="parameters" cascade="all-delete-orphan" lazy="true" sort="natural"> <key column="owning_source" not-null="true" foreign-key="source_params"/> <composite-map-key ...

Strategies to avoid Hibernate LazyInitializationExceptions

Are there any other ways to avoid LazyInitializationExceptions in a Hibernate web application besides using the OpenSessionInView pattern? Are there any downsides to using OpenSessionInView? ...

How to use Hibernate @Any-related annotations?

Could someone explain to me how Any-related annotations (@Any, @AnyMetaDef, @AnyMetaDefs and @ManyToAny) work in practice. I have a hard time finding any useful documentation (JavaDoc alone isn't very helpful) about these. I have thus far gathered that they somehow enable referencing to abstract and extended classes. If this is the case...

Customized naming of columns in JPA relationships

When I make relationsships with JPA using hibernate, some terrible long and ackward column names are generated. Eg. I have the following actionPlan_actionPlanPK, which means that the column actionPlan is a FK that points to actionPlanPK. To make it look just a little bit more neat in the DB I would like if I could give it a name myself, ...

Illegal attempt to associate a collection with two open sessions

Hi all, I'm trying to add a pojo to a collection in another pojo. I'm sure I'm making a really stupid mistake somewhere along the lines but I can't figure out how to solve it. I have a pojo LookupTable which contains a list of Column's: public class LookupTable { private long id; // More properties go here... private List<Column...

xdoclet vs xdoclet2 ?

Hi all, I'm updating an old project & my version of xdoclet complains about my Java 1.5 annontations (ArrayList data = ....) when parsing for Hibernate (hibernate3) tags. So my question is this... Is there a fix for Xdoclet 1.2.3, or should I look to move to Xdoclet2? I've already started moving some of the code over, but xdoclet2 do...

Hibernate: hbm2ddl.auto=update in production?

Is it okay to run Hibernate applications configured with hbm2ddl.auto=update to update the database schema in a production environment? ...

Hibernate: check if object exists

Suppose, objects of type A are stored in DB. Here's the way I load specific one from DB using hibernate: org.hibernate.Session session = ...; long id = 1; A obj = session.load(A.class, id); If object with id=1 doesn't exist I will get ObjectNotFoundException. But is there a way to check if such object exists without having to catch th...

Creation timestamp and last update timestamp with Hibernate and MySQL

For a certain Hibernate entity we have a requirement to store its creation time and the last time it was updated. How would you design this? What data types would you use in the database (assuming MySQL, possibly in a different timezone that the JVM)? Will the data types be timezone-aware? What data types would you use in Java (Date,...

How to use MySQL prepared statement caching?

How do i take advantage of MySQL's ability to cache prepared statements? One reason to use prepared statements is that there is no need to send the prepared statement itself multiple times if the same prepared statement is to be used again. Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysq...

How to stop Hibernate from eagerly fetching many-to-one associated object

I have a property on a domain object that is declared in a many-to-one element. The basic syntax of this property looks like this: <many-to-one name="propertyName" class="propertyClass" fetch="select" not-found="ignore" lazy="proxy" /> Now, the idea is to have Hibernate NOT eagerly fetch this property. It may be null, so the not-fou...

No suitable MySQL driver found for JBoss application

Hello, I am new to creating Java web applications and came across this problem when trying to interact with my database (called ccdb) through my application: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ccdb/ My application runs on JBoss and uses Hibernate to interact with the MySQL database. I have the M...

Creating a custom Hibernate UserType - What does isMutable() mean?

I am creating a custom UserType in Hibernate for a project. It has been relatively straightforward until I came to the isMutable method. I am trying to figure out what this method means, contract-wise. Does it mean the class I am creating the UserType for is immutable or does it mean the object that holds a reference to an instance of ...

Hibernate returns invalid results with composite key.

I'm getting the strangest results. I have a class with a composite key. If i do the following query: from LOVEJB l order by l.canonicalId desc my results are not ordered by the 'canonicalId' column I asked for. Instead, the canonical id result is like: 823 823 822 823 ,,, Can someone give me some pointers on how should I tr...