orm

JPA Adding Logic to Removing an Entity

I am somewhat new to using JPA -- I'll put that out there right off the bat. I'm getting more familiar with it, but there are big holes in my knowledge right now. I am working on an application that uses JPA, and deletes entities using the EntityManager.remove(Object entity) function. However, the application also links into a third-par...

portable lightweight java orm framework for android

Hi all, I am developing portable library on java which will run on mobile device (android, blackberry) . I am looking for lightweight orm framework that i can use here here is list with orm frameworks i found in google http://java-source.net/open-source/persistence . I've used only hibernate and i' not familiar with most of them so any ...

make a entity class rows read-only in JPA

I m able to get values using JPA when i have only mapped one table Now when i have gone for mapping related tables i get the error Only one may be defined as writable, all others must be specified read-only. Mapping: org.eclipse.persistence.mappings.OneToOneMapping[userId1] I m using [EclipseLink-0] (Eclipse Persistence Services...

Refreshing entity instance after using merge in hibernate?

Hi there, am using hibernate merge method, to deal with detached instance from entity, and i thought that the return of this method will be a new fetched instance from database as hibernate saveOrUpdate method, but that wasn't the case, and i think it's logic as it's a detached instance, so is there a better way to return the new instan...

Help with HQL query (group by, order by)

I have problem writing HQL to display distinct applicationId with the latest application (newest createDate) for the following data in the table. +---------------+-------------+----------+---------------------+ | applicationId | firstName | lastName | createDate | +---------------+-------------+----------+--------------------...

select from two tables using JPQL

Hi I m using JPQL to retrieve data. I can get data using the statement List persons = null; persons = em.createQuery("select p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1"); Now i can get the album names using this... int i=0; for (i=0;i<persons.size(); i++) { System.out.println("Testing n "...

How to inject custom object ids into JPA entities

I am using JPA 2 for an enterprise application, and my DBA's just hit me with a twist. They want me to use the group's centralized object ID generator for all my tables. This means rather than using table values or a sequence table, I will need to call a web service to get a batch of ~50 ids. Then, as I persist any new object, I would...

jpql don't load Blob

Hi, I have an entity @Entity @NamedQueries({ @NamedQuery(name = "Item.findAll", query = "select i from Item i"), }) public class Item implements Serializable, WithId, WithNameDescription { @Lob byte[] photo; @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) TextualInfo english = new TextualInfo(); // more e...

JPA: Merge @OneToMany Duplicate entry error

Hi! I'm alwways getting the following error: Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '2-1' for key 'PRIMARY' Error Code: 1062 Call: INSERT INTO ENTITY_ENTITY (relationships_ID, Entity_ID) VALUES (?, ?) bind => [1, 2] Query: DataModifyQuery(sql="INSERT INTO ENTI...

Two queries instead of one, when using LockOption.UPGRADE

I have two entities with one-directional OneToOne relationship. EAGER fetch type is specified. When I load parent entity by id, one sql inner join query is executed. This is right behavior. But when I specify LockOption.UPGRADE, the parent and child entities are loaded in two different queries instead of one. Why this happens? ...

Custom ORM in .NET

Hi I want to call only stored procedures on database and fill my C# object according to the result. I just need a mapping file, and a fast reflection tool like Fasterflect found on CodePlex to create my own ORM. Is there any ORM available with these feature for C# which has lightning fast performance ? or what should I do to complete t...

More condition on hibernate left join clause

How to achieve subquery in hibernate criteria left join? I tried in this way, DetachedCriteria subquery = DetachedCriteria.forClass( Comment.class, "comment").add(Restrictions.eq("comment.divisionId", divisionId)); subquery.setProjection(Projections .groupProperty("comment.commentId")); Session ses...

What does JPA EntityManager.getSingleResult() return for a COUNT query?

What does EntityManager.getSingleResult() return for a COUNT query? So.. what is the precise runtime type of foo? Object foo = em.createQuery("SELECT COUNT(t) FROM com.company.Thing t WHERE prop = :param") .setParameter("param", value).getSingleResult(); ...

Hibernate get single row from the table with maximum field value

Hi Guys, In Hibernate, how can I get single row from the table with maximum field value? Thanks ...

Hibernate: cant get the associated List retrieved

Hi An entity X has a list of entity Y and the entity Y has an instance of entity Z. The relation between X to Y is OneToMany and the relation between Y to Z is ManyToOne. I want to retrieve X and have all the associated entities retrieved with them as well. What HQL query do I write so that I get the whole chain retrieved all at once...

Mapping parent child relationship - composite key formed by fields of two objects

There are three object entities: GrandParent, Parent and Child GrandParent contains grandParentId Parent contains object GrandParent, parentId, some attributes, and a list of Child. Child contains childId and some attributes. There are four tables: GrandParent, Parent, Child, ParentsChildrenList GrandParent whose primary key is {gr...

How can I map a hierarchy in SQLAlchemy with dynamic relationships?

I am defining a SQLAlchemy model like this: class SubProject(Base): active = Column(Boolean) class Project(Base): active = Column(Boolean) subprojects = relationship(SubProject, backref=backref('project')) class Customer(Base): active = Column(Boolean) projects = relationship(Project, backref=backref('customer')) I need to...

How to enable pessimistic locking of related table in OneToOne relation

I have OneToOne relation with lazy loading. I want related entity to be loaded like with LockOption.UPGRADE option, ie with pessimistic locking. How can I do this? ...

Hibernate: specifying which column in parent entity <join/> should use

Hello. I have the following entity in my HBM file: <join table="v_price_change_current_prices" fetch="join" inverse="true"> <key column="product_color_id" /> <property name="oldMSRP" column="msrp" /> <property name="oldList" column="list" /> </join> my PRICE_CHANGE table has an ID column (primary key) and a PRODU...

Modify entity with EntityListener on cascade

Hello. I have a database in which an entity (say, User) has a list of entities (say, List). As a requirement, I must have a denormalized count of the entities on the list: @Entity class User { /* ... */ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<Friendship> friends; public int friendsCou...