orm

How to configure JPA 2.0 with Hibernate 3.5.2 to use EHCache as a Level 2 cache and query cache?

I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. edit// Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity? ...

Which ORM supports mapping existing databases?

So I have a layered ASP.NET MVC proof-of-concept application with good separation between presentation concerns, business logic, and infrastructure concerns. Right now it is operating off of a fake repository (i.e. LINQ queries against static IQueryable objects). I would like to create a functional SQL repository now. That said, I don...

NHibernate / Fluent NHibernate Mapping

Is it possible to map the following situation? A product class (currently a table) An account class (currently a table) An accountproduct class (currently a join table but with additional information related to a specific product and account) What I'd ideally like is accountproduct to extend product and to be available from account a...

How do I cascade deletes to multiple tables in SqlAlchemy?

I have a table with several dependent tables that I want cascade delete. I'm having problems with it cascading too far. Some code will help explain. class Map(Base): .... #One to many relationship between the Map and Tile. #Each Map is made up of many tiles tiles = relationship('Tile', lazy='joined', backref='map', ...

Grails/Hibernate: Null Pointer Exception on versioning

Working with a legacy codebase in Grails. Under some conditions (we're unclear exactly what) we get a mysterious NPE, stack trace as below, while doing a findBy. So far we're sort of stymied; this appears in several fora for Hibernate but the responses seem to come down to "something is wrong with your schema." It would be wonderful t...

Calling a Stored Procedure in Hibernate

I just started learning hibernate last night and its rather fun. I am some trouble calling a stored procedure as a sql-query with hibernate. I have attached the source and the error, please help me. Thanks :) <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "hibernate-...

How to encourage myself to switch to ORM?

I'm working with a legacy project of my team-mate (.NET/Oracle). The project is not yet completed, it's under construction and far from production. He followed a "traditional way" to access data, which is creating stored procedures and then use database driver to call them. I want to follow a "modern way" to access data: use an ORM to ab...

jpa 2 hibernate setting a lock on EntityManager.find

Hi guys: a little strange problem.. I'm doing a few testcases on an hibernate project: when I call EntityManager em = getEntityManager(); em.find(Foo.class, 1) I get the entity as I expect, but when I invoke: EntityManager em = getEntityManager(); em.find(Foo.class, 1, LockModeType.WRITE) I'm getting null. Also, w...

Sorting by (order_by) foreign table value with Kohana ORM.

Is there any way to sort in orm by using a value from a forgin table? Can you do something like orm::factory("table")->order_by("table.foregin_table.column" , "ASC") or do you have to use some regular mysql and join the tables together old school? ...

Calling Oracle functions from EJB in Seam framework

Hi, I am using seam framework and struggling to call a Oracle function. In my EJB, I am creating a namedQuery and when I call my entityManager.getResult() I get the following error: PLS-00222: no function with name 'jjhg' exists in the scope. (jjhg is the name of my oracle function) Please help. This is a bit urgent for me ...

How to log values that Hibernate binds to prepared statements?

How can I make Hibernate log the values it binds to prepared statements? If I set property hibernate.show_sql=true I get following kind of logging: insert into tablename (field1, field2) values (?, ?) I'd like also to know what values are bound to question marks. I am using Hibernate 3.2.7.ga. ...

HIbernate+JPA Composite Key problem: generating select sql with wrong columns

Here is my sample codes. PrimaryKey Class: public class ReplAreaElemDataCompositeKey implements Serializable{ private static final long serialVersionUID = 1L; private int imageElementID; private int variableID; public ReplAreaElemDataCompositeKey() { super(); } /** * @param imageElementID * @param variableID */ public Re...

[Fun riddle] Any clue on this error with generic relation using Django Orm?

This is a fun one :-) Working on an EAV, we inject a generic relationship handler at runtime in a model. model_cls is any class, and a EavValue class have a generic relation pointing to it. It works fine from EavValues to a model_cls, but on the other way we need to inject an accessor to ease things: generic_relation = generic.Generic...

Composite Foreign Key lost in merge() operation (JPA/Hibernate)

Imagine an Employee Entity that references a Department using a Compound Key: @Entity public class Employee { ... @ManyToOne @JoinColumns({ @JoinColumn(name="dept_country", referencedColumnName="country"), @JoinColumn(name="dept_id", referencedColumnName="id") }) private Department dept; ... In a Stateles...

jpa2 hibernate, a testcase to test lock over an entity

Hi!, I'm using Hibernate 3.5.5.Final and JPA2 How can make a testcase to test if the hibernate lock is working? I wrote this, but seems that the test not pass in the current hibernate version (works fine in the previous version) @Test(expected=OptimisticLockException.class) public void testLock() { EntityManager em = getEntityMa...

How to create Id on hibernate entity that is a byte[] that maps to a varbinary value in mysql

I am trying to create an Entity that has a byte[12] id in hibernate. It seems like it does not like to have a byte[] as a primary key and as another column it sets it up as a tinyblob in the backing mysql db. I have tried to create a String, but the problem is that the string in java is 2 bytes per char, while it is one byte per char i...

How do i access an out parameter in a pl/sql proc via hibernate

I have a pl/sql procedure with the following signature PROCEDURE pr_log_process_started ( p_process_id IN log_process_status.process_id%TYPE, p_run_id IN OUT log_process_status.run_id%TYPE); How can i make a call to this proc via Hibernate and access the value of the second parameter after the call? ...

JPA Query toString

Hello SO, I have a JPA Query I am executing on the Google App-Engine datastore. I am building the query using parameters. After all parameters have been inputted, I wish to view the Query String. That is, I wish to view the actual query being executed by the datastore. Is that even possible? It would really help me in debugging. To SOL...

How to properly implement a domain object with composite id in Hibernate?

I have the following domain objects: public class Department { private long departmentId; } public class Manager { private long managerId; } public class Project { private ProjectId compositeId; @ManyToOne private Department department; @ManyToOne private Manager manager; } public class ProjectId...

Django ORM equivalent for this SQL..calculated field derived from related table

I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height = models.DecimalField(max_digits=10,decimal_places=2) class MLog(models.Model): date = models.DateField(db_index=True) time = models.TimeField(db_index=True) ...