jpa

Database not dropped in between unit test

Hello good people i came accross a weird behaviour in my test.I'm using JPA hibernate annotation with spring. let say i have an Class MyObject and it's property email is marqued @Column(name="EMAIL", length=100, unique=true) private String email; i prepare for what i need to be in the database in the setup of this class MyObjectDAOImp...

How to make a weak entity using EJB 3.0

Hi there, suppose I have an entity "Employee", and an entity "Address". An employee has an address associated to him/her. In a relational database sense, the Address table would be considered a weak entity, since an employee address cannot exist if there is no corresponding Employee in the database. Thus, suppose I want to model the fol...

Could I order in EJBQL by a function which is not mapped to a column in database?

Hello everyone, I would like to order a query by a function which uses properties of the class. Something like: @entity class A { private int id; private String name; public int StringLength() { return name.length(); } } And the sentence something like: "select n from A order by name.StringLength()". Is it possible? Thanks in advan...

@IdClass with non primative @Id

I'm trying to add a composite primary key to a class and having a bit of trouble. Here are the classes. class User { private long id; ... } class Token { private User user; private String series; ... } I'm using the orm.xml to map the classes because they're actually part of a higher level API that I don't want to...

hard time setting autogenerated time with hibernate JPA annotations

hello good people! thanks to you guys my knowlegde on hibernate has been improve dratiscally. now i hit a block here about current_timestamp. here is my codes @Column(name="DATE_CREATED", insertable=false, updatable=false, columnDefinition="timestamp default current_timestamp") @org.hibernate.annotations.Generated(value=GenerationTime....

Some limitations about EJB 3.0 and Toplink framework

I have project use EJB 3.0 and implement Toplink framework for model layer. When using EJBQL to process data, I see it seems have some limitation: It cannot process datatime such as find a part of date such as day, month or year It cannot find datetime among from...to It cannot comparison datetime field It cannot map a class not entit...

Making foreign keys unique in JPA.

Hi there, Is it possible to make a foreign key unique within a table? Suppose I have entities A and B. A: @Entity class A extends Serializable { @Id private long id; @OneToOne private B b; } B: @Entity class B extends Serializable { @Id private long id; } I want to make it so that an A can have a B, except there can be no other ...

translating outer join SQL query into EJB entity beans

I'm new to EJB and trying to get my head around translating SQL concepts to EJB entity beans. Suppose I have two tables: PEOPLE (id, name), CONTACT(pid, phone_number). If I want to get a list of all people whether or not they have phone #s, in my EJB session bean I simply issue a SQL query via JDBC such as: SELECT PEOPLE.name, CONT...

JPA Entity Foreign Keys mapped to a Primary Key

Is it possible for a Primary Key of an nested Entity to be used as the Primary Key of the Nest Entity? For Example: If I had a Entity 'Staff' who has a primary key 'EID' and has the nested Entity 'Job'. The Entity 'Job' has a primary key 'JID', and a Discriminator type 'DTYPE' so that sub classes of Job may be stored in the DTYPE alo...

one-to-many JPA annotations won't delete orphans

Hello good people. I 'm trying to build a user and a contact management project. i have a lot of classes so will limit it to what are in concern here. i have a userAccount, userProfile, and group here is the UserAccount Mapping @Id @GeneratedValue @Column(name="USER_ACCOUNT_ID") private Long ID; ...... @Column(name="EMAIL", length=10...

EclipseLink, EntityManager with two persistence units needed

Hi, I have one jar library A (or project in eclipse), which has it's own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is also persistence unit and entity classes. In project B I need to use both entity classes from project A and B. But if I set "A" as pe...

Last update timestamp with JPA

I'm playing around a bit with JPA(Eclipselink to be specific). The below entity have a timestamp that's supposed to reflect whenever that entity was last updated. What are the strategies for making JPA update that timestamp automatically every time this entity is changed ? How would I go about if I also want a 'creation' timestamp, on...

Mapping db-imported countries to address entity with JPA

I ran some DDL script to setup a complete country table in my database. The country table's primary key column contains the corresponding ISO code for every country. In my JPA project I have a User entity having an embedded Address entity and this Address entity has a reference to a Country. The relationship between User and Address se...

Combination of field as unique where one is a one-to-may unidirectional with HIbernate/JPA annotations

hello i'm not sure whether the title depicts the my situation very well.I'm developing a user and contact managment system with hibernate. i have an UserAccount pojo, contact pojo and phone object.i limited it to 3 since since those are in concern.UserAccount has a bidirectional with contact, and both have unidirectional with phone pojo....

Can/should JPA be used to return values rather than entities?

I'm using JPA for a project and in most cases, want to get entities, but there are a few cases (reporting being one of them, but there are others) where I do not want or need to get entities, but rather want a selection of values. Does JPA support this? If so, does it make sense to use it or does it make sense to use straight JDBC in the...

Persisting to SQL Server 2008 using stored procedures, JPA and Hibernate

We are implementing a web page to maintain an organisational structure. The structure is stored in SQL Server 2008 and uses the new HierarchyID data type. Because we have had problems getting JPA and Hibernate to play with this new data type we have decided to use views and stored procedures to abstract away this data type. So we want to...

query must begin with SELECT or FROM: delete [delete

I am using JPA in addition to spring(3.0.0.M4). While deleting multiple records using query.executeUpdate() i am getting the following exception. org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: query must begin with SELE...

how to implement a search from search box?

I've got a requirement where a user enters a few terms into a search box and clicks "go". Does anyone have any good resources on how to implement a dynamic search that spans a few database tables? I am using jsp,servelt,jpa as front end and mysql at back end of my project. Thanks, Satya ...

similarity and difference between jpa and hibernate.

what is similarity and difference between jpa and hibernate. ...

JPA Inheritance Multiple DiscriminatorValues

I am trying to implement JPA with inheritance for an existing database. The current db model is the following: Instrument * InstrumentID * Description * InstrumentTypeID InstrumentType * InstrumentTypeID * StorageClass Option * InstrumentID * (Option specific fields) Stock * InstrumentID * (Stock specific fields) There is...