hibernate

Do I need to use C3P0 pooling library in my (grails) web application?

Hi, I am not familiar at all with connection pooling library. I've just discovered it through this blog article) and I am not sure that I should use one in my web application based on grails/hibernate/mysql. So my question is simple : in which situations would you suggest to integrate a connection pooling library into a grails applica...

JPA @ManyToMany on only one side?

I am trying to refresh the @ManyToMany relation but it gets cleared instead... My Project class looks like this: @Entity public class Project { ... @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "PROJECT_USER", joinColumns = @JoinColumn(name = "PROJECT_ID", referencedColumnName = "ID")...

Hibernate custom join clause on association

I would like to associate 2 entities using hibernate annotations with a custom join clause. The clause is on the usual FK/PK equality, but also where the FK is null. In SQL this would be something like: join b on a.id = b.a_id or b.a_id is null From what I have read I should use the @WhereJoinTable annotation on the owner entity, but ...

Maven archetype for basic spring hibernate struts2 application

Hello I am looking for a basic maven archetype which can help me create a spring hibernate struts2 application. I have tried using appfuse but it sucks. It took more than half an hour to download n number of dependencies and the project it created was having errors also. if you know anyother maven archetype please tell me. Thanks...

Hibernate duplicate primary key on restart using GenerationType.TABLE

We're running into an issue where we have Event subclasses that use GenerationType.TABLE to generate the primary key, and when we restart the servers we are getting duplicate primary key errors. We're using SQL Server and Hibernate version 3.5.1-Final. Here's what our Hibernate annotations look like: @Entity @Inheritance(strategy = In...

Cache for large read only database recommendation

I am building site on with Spring, Hibernate and Mysql. The mysql database contains information on coordinates and locations etc, it is never updated only queried. The database contains 15000 rows of coordinates and 48000 rows of coordinate connections. Every time a request is processed, the application needs to read all these coordinate...

Defining relationship in value objects using Hibernate

Hi, We have three tables .We need to get data from these tables based upon particular conditions. Like if TableA.columv=TableB.columc=tableC.column then get data. We are using value objects to map Objects to relations. Question is how to maintain these relation ships in value objects. And how to retrieve data from it. We have one valu...

LazyInitializationException with @Transactional annotation in MessageConverter

Hi, I have a REST-service exposed through Spring-MVC. I have a particular method which is correctly mapped and called through a HTTP-call. My Spring application contains the HibernateTransactionManager and transactions are configured through @Transactional-annotations. I annotated the method like this: @Transactional(readOnly = true) @...

Hibernate Criteria API: get n random rows

I can't figure out how to fetch n random rows from a criteria instance: Criteria criteria = session.createCriteria(Table.class); criteria.add(Restrictions.eq('fieldVariable', anyValue)); ... Then what? I can't find any doc with Criteria API Does it mean I should use HQL instead? Thanx! EDIT: I get the number of rows by: int max =...

How to make Spring load a JDBC Driver BEFORE initializing Hibernate's SessionFactory?

I'm developing a Spring(2.5.6)+Hibernate(3.2.6) web application to connect to a custom database. For that I have custom JDBC Driver and Hibernate Dialect. I know for sure that these custom classes work (hard coded stuff on my unit tests). The problem, I guess, is with the order on which things get loaded by Spring. Basically: Custom ...

Storing a jpa entity where only the timestamp changes results in updates rather than inserts (desired).

I have a JPA entity that stores a fk id, a boolean and a timestamp: @Entity public class ChannelInUse implements Serializable { @Id @GeneratedValue private Long id; @ManyToOne @JoinColumn(nullable = false) private Channel channel; private boolean inUse = false; @Temporal(TemporalType.TIMESTAMP) private Date inUseAt = n...

How to map a property for HQL usage only (in Hibernate)?

i have a table like this one: id | name | score mapped to a POJO via XML with Hibernate. The score column i only need in oder by - clauses in HQL. The value for the score column is calculated by an algorithm and updated every 24 hours via SQL batch process (JDBC). So i dont wanna pollute my POJO with properties i dont need at runtime....

Hibernate/c3p0 connection leak

We're running a spring/hibernate/c3p0 application under load. When I reduce the c3p0 maxPoolSize to some far, far lower than the number of concurrent users, our application just hangs. There are no error messages in the log, but it doesn't proceed forward either. I expect the application to slow down, but not to stop altogether. Here ...

How does hibernate use an empty string for an equality restriction?

I have a column that potentially has some bad data and I can't clean it up, so I need to check for either null or empty string. I'm doing a Hibernate Criteria query so I've got the following that returns incorrectly right now: Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Criteria myC...

Problem persisting inheritance tree

I have a problem trying to map an inheritance tree. A simplified version of my model is like this: @MappedSuperclass @Embeddable public class BaseEmbedded implements Serializable { @Column(name="BE_FIELD") private String beField; // Getters and setters follow } @MappedSuperclass @Embeddable public class DerivedEmbedded exten...

Hibernate - Envers - Multiple Audit targets

Hi all, I am already using Hibernate Envers to audit entities that are updated by a user through the UI; however, I also have asynchronous jobs running in the background and would like to audit those as well using Envers. Now, for the UI, I track which HttpRequest made the change which gives me the date, user, session, etc. For the ba...

Keep Hibernate Initializer from Crashing Program

I have a Java program using a basic Hibernate session factory. I had an issue with a hibernate hbm.xml mapping file and it crashed my program even though I had the getSessionFactory() call in a try catch try { session = SessionFactoryUtil.getSessionFactory().openStatelessSession(); ...

disable hibernate logging in cosole

Hi, My log4j.properties looks like log4j.rootCategory=DEBUG, A1 log4j.appender.A1=org.apache.log4j.RollingFileAppender log4j.appender.A1.File=InteroperabilityFatal.log log4j.appender.A1.MaxFileSize=1000KB log4j.appender.A1.MaxBackupIndex=1000 log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionP...

Hibernate database integrity with multiple java applications

We have 2 java web apps both are read/write and 3 standalone java read/write applications (one loads questions via email, one processes an xml feed, one sends email to subscribers) all use hibernate and share a common code base. The problem we have recently come across is that questions loaded via email sometimes overwrite questions cre...

write behind cache Ehcache new feature?

Hi, i looking for guide/document/tutorial on how to use this new feature write-behind-cache in ehcache? Is there any demo in spring+jpa+ehcache+hibernate? just to clariyfing, write-behind-cache mean each time we persist entity, it will be written into cache rather than into database correct? ...