I have the following many-to-many mapping:
public class Student implements
{
@Id
@GeneratedValue
private Integer xID;
@ManyToMany
@JoinTable(name = "x_y",
joinColumns = { @JoinColumn(name = "xID")},
inverseJoinColumns={@JoinColumn(name="yID")})
private Set<Cat> cats;
}
public class Cat implements
{
@Id
...
I need to allow client users to extend the data contained by a JPA entity at runtime. In other words I need to add a virtual column to the entity table at runtime. This virtual column will only be applicable to certain data rows and there could possibly be quite a few of these virtual columns. As such I don't want to create an actual add...
I have a DSL Java object, i.e. a POJO which returns this in setters plus the getters/setters have an unusual naming pattern:
public class Demo {
private long id;
private String name;
private Date created;
public Demo id (long value) { id = value; return this; }
public String id () { return id; }
public Demo name...
I'm currently using Java EE to inject my EntityManager into a web app as follows:
@PersistenceContext
EntityManager em;
@Resource
UserTransaction utx;
I have this in a request scoped JSF bean. It works, but it's a pain because to avoid the NoTransactionException I have to wrap every DAO method like so:
public void saveSomething(Obj ...
In eclipse, the "default implementation library" what jars files do I need to include if I do not want to use server runtime?
I'm refering to this tutorial http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jpt.doc.user/task_create_new_project.htm
...
I'm using MySQL and have the following entity:
class MyEntity {
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="id")
private Integer id;
}
However, I would still like to be able to set the id manually!
The problem is that INSERT will never insert the id column. E.g., when
doing this:
MyEntity e = new MyEntity();...
I have this code:
run big query: Select all unprocessed objects from table A
for each result
create or update an output object in table B
update input object: Set it to "processed"
I'd like to have a transaction over the loop body, that is after one row of input is processed, the updated objects should be committed, so when th...
Can some explain to me what is the advantage of using detached objects within the context of a web application? AFAIK they are only useful if the objects somehow outlive the "lexical" scope of the transaction, but typically in a web app when your transaction is over you just send your objects to the view layer, and they will not be reatt...
In the following code I am trouble with my injected EnitityManager, which always shows up as null;
public class GenericController extends AbstractController {
@PersistenceContext(unitName = "GenericPU")
private EntityManager em;
protected ModelAndView handleRequestInternal(
HttpServletRequest request,
...
Hi,
hibernateSession.createQuery("select foo where id = 1");
// This command return the Item with id 1.
// [BREAK POINT STOP] ==> I go in MySQL and I delete this item manualy.
// [BREAK POINT CONTINU]
hibernateSession.createQuery("select foo where id = 1");
// This command return the Item with id 1 too ! :-(
It's the same with hibern...
Hi all,
I have written the following code:
@Entity
@Table(name="person")
@Inheritance(strategy=InheritanceType.JOINED)
public class Person {
private Long id;
protected String email;
private String firstName;
private String lastName;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {...
So, I'm not sure how to ask this question, as it seems like it should be pretty easy to find the answer to this one.
I have 3 tables; ContentHeader, ContentType1 and ContentType2. ContentHeader has a primary, auto-increment key. ContentType1 and ContentType2 both maintain foreign keys to ContentHeader's primary key. These foreign keys ...
I'm configuring JPA to work with SQLite db, with hibernate as the provider. I map a single pojo to a table, no fk's,just plain simple for now. I'm using a SQLDialect I found on the internet.I get this stacktrace, when I try to initialize my application:
java.sql.SQLException: SQLite supports only TRANSACTION_SERIALIZABLE
at org.sql...
(note: I'm quite familiar with Java, but not with Hibernate or JPA - yet :) )
I want to write an application which talks to a DB2/400 database through JPA and I have now that I can get all entries in the table and list them to System.out (used MyEclipse to reverse engineer). I understand that the @Table annotation results in the name...
Having a hibernate mapping a legacy database I want to use EnumTypes to map certain columns that contain string constants with whitespace to some Enum class.
The mapping:
@Entity
@Table(name = "OPERATOR")
public class Operator {
@Id
@Column(name = "ID")
private Long id;
...
@Enumerated(EnumType.STRING)
@Colu...
com.something.SuperClass:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
private static final long serialVersionUID = -695503064509648117L;
long confirmationCode;
@Id
@GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
p...
Given the following:
@Entity
public class Parent implements Serializable {
@Id
private Long id;
// mapped ManyToOne below...
private List<Child> children = new ArrayList<Child>();
...
}
Is it a bad practice to have Parent.equals() and Parent.hashCode() use only id? I understand that Child.equals() and Child.hashCode() shou...
I'm getting LazyInitializationException with session scoped bean in my service layer. If I load the same bean using a regular dao in my method, I can access it's lazy collections without problems. But if I inject it in my service bean, and then try to access one of its lazy collection, I have a LazyInitializationException.
I'm using J...
Consider the following JPA entity. My application instance class must always have a OneToOne reference to 4 special instances of Envelope but it also has a set of 0-infinite user defined envelopes. Is this even possible? Is it possible with both Unidirectional and/or Bidirectional references?
@Entity(name = "Application_Instance"...
@Entity
public class TestClass implements Serializable{
private Integer id;
private Set<String> mySet;
@Id
@GeneratedValue
public Integer getId() {
return id;
}
@OneToMany(cascade={CascadeType.ALL})
public Set<String> getMySet() {
return mySet;
}
}
I get the following error.
Caused by: or...