I am learning JPA from this tutorial.
I have some confusions in understanding the following annotations:
@Basic
@Embedded
Fields of an embeddable type default to persistent, as if annotated with @Embedded.
If the fields of embeddable types defualt to persistent, then why would we need @Embedded
...
Hi,
When using Persistence frameworks like Hibernate, JPA etc. on the server side, what are the general practices of passing on the data between client and server ? Are there any existing design patterns for the same ?
Thanks.
...
I have an entity with a transient field. When I want to create a new instance of the object I lose my transient information. The following example demonstrates the issue. For the sake of the example let's say that barness is a transient field.
FooEntity fooEntity = new FooEntity();
fooEntity.setFoobosity(5);
fooEntity.setBarness(2);
...
Environment: Jboss, Mysql, JPA, Hibernate
Our web application will be catering to a large amount of users (~ 1,000,000) and there are a lots of child table where user specific data are stored (e.g. personal, health, forum contributions ...).
What would be the best practice to archive user & user specific information.
[a] Would it be...
In these examples on TopLink JPA Annotation Reference:
Example 1-59 @OneToMany - Customer Class With Generics
@Entity
public class Customer implements Serializable {
...
@OneToMany(cascade=ALL, mappedBy="customer")
public Set<Order> getOrders() {
return orders;
}
...
}
Example 1-60 @ManyToOne - Order Cla...
I just wanted to hear the opinion of Hibernate experts about DB schema generation best practices for Hibernate/JPA based projects. Especially:
What strategy to use when the project has just started? Is it recommended to let Hibernate automatically generate the schema in this phase or is it better to create the database tables manually ...
Hello
i am wondering how i would be able to annotate an interface
@Entity
@Table(name = "FOLDER_TABLE")
public class Folder implements Serializable, Hierarchy {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "folder_id", updatable = false, nullable = false)
private int fId;
@Column(name = "folder_name")
private St...
I am learning JPA and have one question:
In which situations we need more than one EntityManager in our application?
The two situations that I am aware of are as follows:
When our application is a multi-threaded application and more than one thread needs JPA transaction because EntityManager is not thread-safe and we need one EntityM...
I am learning JPA. I read about persistence.xml file. It can contain more that one <persistence-unit> tag under <persistence> tag.
Upto my undestanding, <persistence-unit> defines:
db connection settings
classes(entity classes), jar files, and mapping files
provider information
Then why would we need to group the entities of our app...
I'm following the guide here, but when the DAO executes, the EntityManager is null.
I've tried a number of fixes I found in the comments on the guide, on various forums, and here (including this), to no avail. No matter what I seem to do the EntityManager remains null.
Here are the relevant files, with packages etc changed to protect ...
Fields in a DB were of type DATETIME (mysql).
Why was it generated as a timestamp and will it be regenerated
during object persistence? That is not a desired scenario in my case,
seeing that as not a timestamp field means that it should only be set via setter,
no generation needed, I dont really understand why it did not generate it...
I have a Story entity with the following associations:
Story <1-*> Chapter
Story <1-*> Comment
Story <*-1> User
What is the correct way of removing this entity and handling the all the entities that is referring to? Is there some shorthand way of specifying that associated entities must be handled automatically or is the @PreRemove a...
All what Hibernate reverse engineering generates is something like this
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "column_id")
public Itinerary getColumnId() {
return this.columnId;
}
I want this scenario: when session flushes, first all constructed childs were saved, then the parent object, accord...
Hello everyone,
I have trouble understanding how to avoid the n+1 select in jpa or hibernate.
From what i read, there's the 'left join fetch', but i'm not sure if it still works with more than one list (oneToMany)..
Could someone explain it to me, or give me a link with a clear complete explanation please ?
I'm sorry if this is a noo...
It is possible to use Java class files which includes annotations that are not present at runtime?
Example: I want to write a class with the JPA @Embeddable annotation, which would be present at compile time (maven scope: "provided"). But the annoatation definition could be absent at runtime, if the class is used outside a JPA applicati...
I want to fetch the id of a one-to-one relationship without loading the entire object. I thought I could do this using lazy loading as follows:
class Foo {
@OneToOne(fetch = FetchType.LAZY, optional = false)
private Bar bar;
}
Foo f = session.get(Foo.class, fooId); // Hibernate fetches Foo
f.getBar(); // Hibernate fetch...
I'm having trouble figuring out how to represent the following JPQL query:
SELECT count(e) FROM Foo e
using Criteria API. What I'm trying is:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Foo> c = cb.createQuery(Foo.class);
Root<Foo> f = c.from(Foo.class);
c.select(cb.count(f));
but this is not working. I also tried:
...
Hi,
The 'DiscriminatorColumn' annotation isn't creating any column in my parent entity. Where am I going wrong ?
Here's my code
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING,length=20)
public class WorkUnit extends BaseEntityClass implements Serializab...
I am learning JPA and have confusion in the @SequenceGenerator annotation.
Upto my understanding, it automatically assigns a value to numeric identity fields/properties of an entity.
Q1. Does this sequence generator make use of the database's increasing numeric value generating capability or generates the number on his own?
Q2. If JPA...
I am reading Hibernate in Action and the author suggests to move business logic into our domain models (p. 306). For instance, in the example presented by the book, we have three entities named Item, Bid, and User and the author suggests to add a placeBid(User bidder, BigDecimal amount) method to the Item class.
Considering that usually...