hibernate

auto incremented number generation for a non primary key column

I have used the following id generation strategy for primary keys. @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false) private Integer id; I would like to do the same for a non primary key column. [a] What would be th...

JPA + Hibernate + Named Query + how to JOIN a subquery result

Hi, Can anybody help me in converting the following native query into a Named Query? Native Query: SELECT usr1.user_id, urr1.role_id, usr2.user_id, urr2.role_id, usr1.school_id, term.term_name, count(material.material_id) as "Total Book Count", fpc.FOLLETT_PENDING_COUNT as "Follett Pending Count", rrc.RESO...

HQL Min Max, how to

Hi, I have two object : "Mother" and "Child". Mother have many Children, How can i get from the DB a Mother with only 2 Children (or less), the younger and the older. Thanks edit: The mother i want to get have a lot of children but i only want the younger and the older. Something like that : from Mother m left join m.Child c where (m...

Hibernate Annotation for Entity existing in more than 1 catalog

I have a Person entity mapped by Hibernate to a database table in a database catalog "Active". After a period of time, records in this database table in the "Active" catalog are archived/moved to an exact copy of the table in a database Catalog "History". I have the need to retrieve from both the Active and History Catalogs. Is there ...

hibernate.properties classpath conflict

I have a jar on the classpath which contains a hibernate.properties. This causes problems when my app starts because hibernate tries to use the settings from this file. Is there a way to explicitly specify the file that hibernate should look for, or tell it to ignore the properties file in the dependency jar? ...

Hibernate sessionFactory rebuilt for each unit test (using spring framework)

I'm using Spring's AbstractTransactionalDataSourceSpringContextTests for my persistence unit tests and my problem is my tests are too slow: 1 method=5s, and each additional method is at least another second. I've over 300 db tables so a slow startup is perhaps understandable. However I've gone through the logs and one of the surprising t...

How to query by embedded example containing null values using hibernate?

I have a problem with a query using hibernate. The entity class EntityClass has an embedded property embedded of type EmbeddedClass and this property has a nullable property optional. When all properties are set, i can do a very simpel HQL query as: Query query = getSession().createQuery( "FROM EntityClass t WHERE t.embedded = :embe...

What approach should I take to understand a large J2EE application if I don't know any of the frameworks involved yet?

I started working in my company 5 or 6 years ago as a junior Java developer, and I got to do some J2EE programming using Servlets and Jsp. I didn't spend much time in that position and I went to work with databases, so I distanced myself from the software development world. Now I've had to go back to Java programming, and I was given a W...

How do I left join tables in unidirectional many-to-one in Hibernate?

I'm piggy-backing off of http://stackoverflow.com/questions/2368195/how-to-join-tables-in-unidirectional-many-to-one-condition. If you have two classes: class A { @Id public Long id; } class B { @Id public Long id; @ManyToOne @JoinColumn(name = "parent_id", referencedColumnName = "id") public A parent; } ...

How is my id being generated with JPA using Hibernate with the Oracle 10g dialect?

I have some code: @Id @SequenceGenerator(name = "SOMETHING_SEQ") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SOMETHING_SEQ") @Column(name = "SOMETHING", nullable = false) private Long id; How is hibernate providing my id? I see in my database there a single sequence named 'hibernate_sequence' and no other hibern...

Hibernate tool to create basic mappings based on a mysql db

Are there any tools that can look at a database, and generate the basic mapping files? It would be great if it could take a database, and create the actual model (java classes) with annotations, but not sure if that exists? ...

Hibernate bug using Oracle?

Hello, I've got the problem, that I use a property in the persistence.xml which forces Hibernate to look only for tables in the given schema. <property name="hibernate.default_schema" value="FOO"/> Because we are using now 4 different schemas the actual solution is to generate 4 war files with a modified persistence.xml. That not v...

JPA + Hibernate + Native Query + custom list of dtos from the resultset

Hi, My native query below is working fine oracle sqlplus. But through JPA native query, giving following error: [ERROR] org.hibernate.util.JDBCExceptionReporter - ORA-00923: FROM keyword not found where expected Native Query SELECT sch.school_name, term.term_name, count(material.MATERIAL_ID), sip.SIP_COUNT, ... FROM VA_SCHOOL sch ...

Generating a SWING/Gui from Hibernate

Hi All, is there any tool that would read a something like a hibernate mapping file and would then create some stubs of java code for a java Swing client ? Thanks, ...

Question about hibernate-spring-dao

I have a DAO class which I'm using to try select/update/insert with hibernate and Mysql database. I'm writing methods for these now, I already wrote insert like this : public Long save(People transientInstance) { log.debug("Saving People instance"); try { Long id = (Long)getHibernateTemplate().save(transientI...

Testing DAO built with Criteria API using Jmock

I'm trying to unit test my DAO which uses the Criteria API. The Criteria object I have has a number of expressions and returns a unique result. The problem I have is that when I use Jmock to create an expectation I have to create one for the criteria.uniqueResult() command and I have to set a return type. The return type is a custom ty...

bi-directional o2m/m2o beats uni-directional o2m in SQL efficiency?

Use these 2 persistent CFCs for example: // Cat.cfc component persistent="true" { property name="id" fieldtype="id" generator="native"; property name="name"; } // Owner.cfc component persistent="true" { property name="id" fieldtype="id" generator="native"; property name="cats" type="array" fieldtype="one-to-many" cfc="cat" casc...

Hibernate many to many join

Ok, Class A can have many Class B. Class B can have many Class A Class A { @ManyToMany( mappedBy="as", targetEntity=B.class, fetch=FetchType.LAZY ) List bs; } Class B { @ManyToMany( mappedBy="bs", targetEntity=A.class, fetch=FetchType.LAZY ) List as; } now I want to select som...

JPA and hibernate for Flex

I'm using JPA but I'm not sure how to use it for relation between two classes. I need to connect them @OneToMany. I have done this before but forgot. Is there any good tutorial for this or an example that is easy to understand. By the way this is a Flex application where I'm using BlazeDS for connection between Java and Flex. ...

Hibernate session not getting created.

Hi all, I am trying to a run an application with Hibernate annotation. I am getting the following exception Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1 Exception in thread "main" java.lang.ExceptionInInitializerError at tapes.test.validation.SessionUtil.<clinit>(Se...