The goal is to remove all Dependent when their Owner is deleted. I have the following classes:
@Entity
class Dependent {
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY, optional = false)
@Column(name = "OWNER")
private Owner _owner;
}
@Entity
class Owner {
...
}
In the current implementation Dependen...
Hi all,
As I am using using mysql database and I am using id strategy.
@GeneratedValue(strategy =
GenerationType.TABLE
and I found that using jpa xml can define a application level generator from the below link
http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/hibernate/Annotations%5FReference%5FGuide/Overriding%5...
I have a strange use case of Hibernate where in a call farther up a large stack needs an unmodified copy of an object that is part of a hibernate transaction. however, every time I ask Hibernate for a copy of the object, it's returning the version that's already been modified / is part of the transaction.
Is there a way for me to force...
Hi,
I want to duplicate a collection of entities in my database.
I retreive the collection with:
CategoryHistory chNew = new CategoryHistory();
CategoryHistory chLast = (CategoryHistory)em.createQuery("SELECT ch from CategoryHistory ch WHERE ch.date = MAX(date)").getSingleResult;
List<Category> categories = chLast.getCategories();
chN...
Lets say we have this JPA-annotated class, with a property of type List. This code is currently working fine.
@Entity
public class Family {
...
@CollectionOfElements(targetElement=java.lang.String.class)
@JoinTable(name = "elements_family",
joinColumns = @JoinColumn(name = "idFamily")
)
@Column(name = "elemen...
I am using Hibernate annotations and entity manager (JPA) with HSQLDB. So I have an entity with an enum field:
@Enumerated(EnumType.STRING)
@Column(name = "access_level")
public AccessLevel getAccessLevel() {
return accessLevel;
}
Where AccessLevel is an enum. I can persist this, detach, and then query and everything is as it sho...
I am getting into App Engine development right now with Java and I am wondering what people think about using the low level api instead of JPA? I understand that JPA may make the solutions more portable in the future but I don't anticipate taking my code anywhere else.
Is it ok to use the low level api instead of JPA? I'm interested in ...
I'm trying to use JPA's Context Injection. Currently my code fails to have the context injected, throwing a NullPointerException:
Exception in thread "main"
java.lang.NullPointerException at
learn.spring.dao.ListingDao.findById(ListingDao.java:19)
Below is my code, anyone see what is wrong/missing? Thanks.
Spring Configuration...
Is there a way to initialize the EntityManager without a persistence unit defined? Can you give all the required properties to create an entity manager? I need to create the EntityManager from the user's specified values at runtime. Updating the persistence.xml and recompiling is not an option.
Any idea on how to do this is more than we...
Hello,
I want to achieve basic CRUD operations available of the db schema I already have for a JAVA program. To put it in another way, I have a DB schema I use with PHP and I just need them to be entities available in a JAVA application. I discovered I can use Netbeans and sucessfully created Entities from DB!
(Entities look like this...
How do you track the number of times a particular entity (say a user profile much similar to stackoverflow.com) is viewed by other users? Would it make sense to update this information when an entity is viewed using a lifecycle event like PostLoad.
Where would you store the number of times the entity has been viewed, would it be in the ...
Problem: Entities (say Users) are showed in a paginated fashion in the UI. The UI also shows a checkbox against each entity, so that it is possible for the admin to multi-select users and delete them. It is quite natural that this entity is associated with many other entities via a foreign key relationship (say Purchase Orders created by...
My persistence.xml has 2 persistence-units. Each of them has several <class> elements.
I thought that we must specify all classes related to certain persistence-unit. But I accidentally forgot to specify class-element for new entity but the program worked fine even without it. Then I removed all class-elements and everything worked fine...
General case: first table represents one-side, second table represents many-side. Third table serves as a link between the two.
My case: first and second tables are the same. Third table serves as a link between all pairs of tables which have one-to-many relationship. This third table has additional field (String) which contains inform...
Hi. I have an insertOrUpdate method which inserts an Entity when it doesn't exist or update it if it does. To enable this, I have to findByIdAndForeignKey, if it returned null insert if not then update. The problem is how do I check if it exists? So I tried getSingleResult. But it throws an exception if the
public Profile findByUserNam...
Hi All,
I'm just starting to take a look at java persistence (at the moment with eclipse's default provider of eclipselink). Basically just creating an object and attempting to persist it to the db (Oracle). It was my understanding that the default transactionality should commit the new object to the database when the method retur...
I have a class User that can have many loginNames:
@Entity
public class User {
@ElementCollection
private List<String> logins = new ArrayList<String>();
}
I want to ensure that each login is unique in the system when a user registers. When someone logs in the user object should be found by the login name. So the elements in the ...
The question is in the title.
Some explanation: I can't implement necessary mapping. But I can get all necessary data using queries in DAOs. So, I want to insert that data manually to my entity in DAOs findAll () method.
But JPA treats all entity's fields as persistent attributes and adds them to generated sql-queries. Of course, I get...
Say I have a Customer - CustomerOrder one-to-many bi-directional relationship with the CustomerOrder holding the total value of each order.
If I had a query to find the total value of all orders for a particular customer :
select SUM(o.orderValue) from CustomerOrder o where o.customer = :customer
Does it matter in which entity class ...
Hi,
i have a problem with a simple @OneToMany mapping between a parent and a child entity. All works well, only that child records are not deleted when i remove them from the collection.
The parent:
@Entity
public class Parent {
@Id
@Column(name = "ID")
private Long id;
@OneToMany(cascade = {CascadeType.ALL}, mappedBy...