hibernate

Automatic test asserting that a property is really lazy with hibernate

Hi, I have to add a lazy=true to a property & i have add a ant task to intrument the class to enable hibernate to make it lazy in my pom. is there a way to test that now this property is in lazy mode in runtime without watching the hibernate sql console output? I mean with unit testing (im using spring test with junit). I dont want to ...

Unit testing the hibernate mapping file

Just curious to know if there is any framework that helps to test the hibernate mapping schema. I've found ORMUnit, used in "POJOs in Action", but it doesn't seem to be in use much. Is there any other framework that people use to make sure that the classes are mapped properly to the database schema, or is this something that people don...

Using HSQL in-memory database as JPA datasource

I have an in-memory data source: java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", ""); emf = Persistence.createEntityManagerFactory("manager"); But now I'm stuck. I want to use it as a JPA data source in a J2SE application. I've scoured the entire web but all info is related to J2EE. <pe...

Webservices with Maven, Spring and Hibernate

I am developing an application using Hibernate, Spring and JaxWS. I was using JaxWS 2.1 and everything was running smoothly .. I need to upgrade to JaxWS 2.2 so I could use the @XmlElement annotation to require a parameter @XmlElement(required=true) .. So I updated my pom file <!-- <dependency> <groupId>com.sun.xml.ws</g...

why my schema.ddl is empty after hibernate3-maven-plugin?

This is the directory structure of the project (maven2 is used): pom.xml /src /main /java Abc.java /resources hibernate.cfg.xml database.properties /META-INF persistence.xml /test /java AbcTest.java /resources database.properties This is the content of hibernate.cfg.xml: ...

hibernate search lucene - Creating Index throwing Synchronization Error

When trying to create Index from the database using hibernate search the below is error is getting shooted. Code snippet used to generate the index: FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager()); fullTextEntityManager.createIndexer().startAndWait(); Below is the error log: SEVE...

Benefits of Hibernate over just generated DAL based on db tables and sprocs?

What are the benefits of Hibernate over just generated DAL based on db tables and sprocs? i.e. writing or using a tool to generate code for the data access layer versus using hibernate ...

what is the purpose of two config files for Hibernate?

This is my current project structure: pom.xml /src /main /resources hibernate.cfg.xml /META-INF persistence.xml I have very similar configuration params in both files (hibernate.cfg.xml and persistence.xml), which looks strange, but this is what I saw in many online examples and tutorials. I can't understand ...

How to inject PersistenceContext during unit testing?

This is my java class: public class Finder { @PersistenceContext(unitName = "abc") EntityManager em; public boolean exists(int i) { return (this.em.find(Employee.class, i) != null); } } This is the unit test: public class FinderTest { @Test public void testSimple() { Finder f = new Finder(); assert(f.exists(1) =...

Hibernate 2, Using Criteria to order by associated property

I've been able to successfully do this with Hibernate3, but cannot find the corresponding syntax in Hibernate2, and am wondering if it's even possible. Criteria crit = session.createCriteria(User.class). createAlias("organization", "organization"). addOrder(Order.asc("name")); Hibernate2 doesn't support FetchMode.JOIN, and the abo...

How to manage database settings from within a Spring MVC web application?

I have been working with Spring Framework 3.0 for the last couple weeks and have been really impressed. This is my first project with Java. My main problem is that I can't find a way to let the end user manage their own database connection from within the web application. The project I am working on will be installed on the client's comp...

Hibernate and generics

In Java I have a class tha has a payload of type T public class GenericStatus<T> { private MyDateRange myDateRange; private T payload; At runtime T can be either a simple primitive Integer or a class called Price where Price is a class with 2 integers public class Price implements Serializable { private int adult; priva...

How to make an optimal hibernate query with three objets ?

I have a query but I dont know how to make it optimal. I have three objects. SCP Question : it has a field that points SCP (SCP_id) Answer : it has a field that points Question (question_id) How can I make a query that counts the number of answer within a given SCP ...

binding multiple values in hibernate using play framework

I am trying to build query in Play framework, I have select * from Candidate c where (:schools member of c.schools) After I bind :school with List with one element it returns result, but if I bind List with multiple elements nothing happens. Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector} [select...

Problem using nested avg(..) aggregate function in hibernate hql

I am using HQL to get data through DAO class but it throws as error stated below : ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected AST node: query Below is my Hql Query : select new com.shaikh.dto.UserResult ( user.userSurName, avg((select avg(v1.age) from com.shaikh.dto.UserResult v1 where v1.joinDate between to_date(:dayF...

Modelling a triple-join column in Hibernate an alternative way

Hi! I have a problem with mapping a triple join table as a map with Hibernate using annotations. I have 3 tables: project, group, role and triple join table project_group_role with columns project_id, group_id, role_id (the primary key is a pair of project_id and group_id). Database structure is given strictly from supervisor, so I'd rat...

Grails ignores hibernate.cfg.xml

Actually I deployed my grails application on two tomcat instances. Now I ran into a problem. My Quartz Job needs to be clustered. I read the plugin documentation and found a possibility to cluster the Quartz jobs in combination with the database. Therefore I have to create a hibernate mapping ('grails-app/conf/hibernate/hibernate.cfg.x...

Mapping same class relation

Hi I’m trying to map some classes in hibernate there and have general problem how such mapping can be done. There is User class and Facebook user class which has the following structure User Class : public class User{ public User(){} Long Id; String FirstName; String LastName; .... FbUser fbuser; //// all requred getters and ...

DB changes listener and web page poll on this changes

I am using Struts2, Spring and Hibernate. Can someone please help me to update the webpage automatically when there is an DB update. Update to DB may not be from application as well, it may be directly to DB. So I need to know the DB update changes and other is how to poll the changes to web page. Thanks in advance ...

How and who should inject PersistenceContext when running tests through Jersey/Grizzly?

I have this class (mix of JAX-RS/Jersey and JPA/Hibernate): public class Factory { @PersistenceContext(unitName = "abc") EntityManager em; @Path("/{id}") @GET public String read(@PathParam("id") int i) { return em.find(Employee.class, i).getName(); } } This is the unit test: public class FactoryTest extends JerseyTest...