jpa

JPA - map entity to sql query?

Hi, I'm writing a JPA connector to a legacy sistem. The problem is, DB design in the system is.. well.. horrible. I need to implement an entity that maps to three tables. I can do it using named sql queries, but the probem is, I have to use this entity in a OneToMany relation (this entity is on the many side). So how do I tell JPA it n...

Hibernate/JPA Annotations -- Unknown Entity

An application that has been working well for months has stopped picking up the JPA @Entity annotations that have been a part of it for months. As my integration tests run I see dozens of "org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem" type errors. It isn't clear to me what's gone wrong here. I have no hiber...

Hibernate JPA Sequence (non-Id)

Is it possible to use a DB sequence for some column that is not the identifier/is not part of a composite identifier? I'm using hibernate as jpa provider, and I have a table that has some columns that are generated values (using a sequence), although they are not part of the identifier. What I want is to use a sequence to create a new...

JPA mapping interfaces

Hello All I am having trouble creating a mapping when the List type is an interface. It looks like I need to create an abstract class and use the discriminator column is this the case? I would rather not have to as the abstract class will just contain an abstract method and I would rather just keep the interface. I have an interface le...

Hibernate JPA to DDL command line tools

There are Hibernate tools for mapping files to ddl generation; ddl to mapping files and so on, but I can't find any command line tools for simple DDL generation from JPA annotated classes. Does anyone know an easy way to do this? (Not using Ant or Maven workarounds) ...

Persisting using hibernate/JPA

I have been working with hibernate/JPA on JBoss for some months now and have one question that I can't find an answer or solution for. It seems like when creating new entity beans I'm not able to do a query before I at least have called EntityManager.persist(entityBean), or else I get the following error: TransientObjectException: obje...

How to persist a property of type List<String>in JPA

What is the smartest way to get an entity with a field of type List get persisted? Command.java package persistlistofstring; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.G...

How to create project in WebLogic Workshop with support for JPA entity beans?

How to create a project in WebLogic Workshop (version 10.3) with support for JPA entity beans? I am trying create a separate EJB and EJBClient projects in Workshop and EJB3 session beans work just fine, but I am having problems with JPA entity beans. It seems that when creating a new project you can add support for JPA and BEA Kodo if...

JPA database error???

When I left Friday my Enterprise app was working fine, I come in today and restart and now I am getting this error: java.lang.ClassCastException: com.sun.enterprise.naming.SerialContext cannot be cast to javax.sql.DataSource at oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:129) at oracle.toplin...

Auto generate data schema from JPA annotated entity classes

I'm using JPA (Hibernate's implementation) to annotate entity classes to persist to a relational database (MySQL or SQL Server). Is there an easy way to auto generate the database schema (table creation scripts) from the annotated classes? I'm still in the prototyping phase and anticipate frequent schema changes. I would like to be able...

JPA/Hibernate in Java SE 6, Best Practices for data access

I am starting a normal Java SE project and i am planning to use JPA/Hibernate. I was wondering if anyone could enlighten me as to what is considered the best way to interact with Hibernate in this environment (data access layers)? ...

How to close EnityManager when not injected?

I have a servlet running in an Oracle OCCAS server. Currently I map some data in a database to an entity class in my application using @Entity annotaion. I fail to inject the EntityManager (@PersistenceContext) though, and to my understanding that is because it is running in my servlet context and not as a separate Entity EJB. Creating t...

JPA CascadeType.ALL does not delete orphans.

I am having trouble deleting orphan nodes using JPA with the following mapping @OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner") private List<Bikes> bikes; I am having the issue of the orphaned roles hanging around the database. I can use the @org.hibernate.annotations.Cascade Hibernate specific tag ...

Hibernate: Automatically creating/updating the db tables based on entity classes

I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue import javax.persistence.GenerationType @Entity public class ServerNode { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id String firstName String lastName } and m...

ejb3-persistence.jar source

Well, I must be brain-damaged, because I can't find the java source for Sun's persistence.jar or JBoss's ejb3-persistence.jar JPA package. They are open-source aren't they? I looked all over the java.sun.com site as well as the GlassFish wiki, but came up empty. I'd like a src.zip or folder like Sun delivers with Java JDKs. Of course...

java.lang.UnsupportedOperationException in JPA transaction

I'm pretty sure that I'm not understanding something about JPA (I'm using OpenJPA) and it's causing this problem. I want to make a copy of a Job entity. @Entity @Table(name="Job") public class Job implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; @ManyToOne private Job ...

Automatic entity mapping similar to O/R-mapping with JSF?

With JPA I do not need to code the SQL for every new attribute as the o/r-mapping is being done automatically. As I am new to JSF, i am wondering whether there is a similar possiblity with JSF? I do not want to add new code to a jsf datatable every time I change something at the corresponding entity. ...

JPA/Hibernate mapping to store months and days-of-months

I have following POJOs: class Month { long id; String description; List<Day> days; // always contains 29, 30 or 31 elements } class Day { byte nr; // possible values are 1-31 String info; } Is there a way to store these objects into following DB structure using JPA+Hibernate: Table MONTHS: id;description; Table...

Help I have problem with select query in JPA

i have problem i want to select name_magazine from magazine and i already import all library needed and Query q = EntityManger.createQuery ("SELECT name_magazine FROM Magazine"); List results = (List) q.getResultList (); For(Sting s : result) System.out.println(s); but when i run this code it's error. can someon...

How do I override the GenerationType strategy using Hibernate/JPA annotations?

I'm considering using Annotations to define my Hibernate mappings but have run into a problem: I want to use a base entity class to define common fields (including the ID field) but I want different tables to have different ID generation strategies: @MappedSuperclass public abstract class Base implements Serializable { @Id @Col...