persistence

Which are the differences/similarities between hibernate and other frameworks or specifications?

限于喜欢 提交于 2019-11-30 16:42:37
I want to know the differences/similarities between Hibernate and simple persistence in Java EE 5? I'm not clear if Hibernate implements Java EE 5 persistence implementation or if it is a totally different approach to data representation over back-end systems. I'm confused about Hibernate and its relation with the concepts about java persistence given in the Java EE 5 tutorial... could you clarify the role of Hibernate in the context of Entities and EJBs? Also, I want to know other approaches (frameworks) like JPA or Spring... Pascal Thivent I want to know the differences/similarities between

Can not set java.lang.Integer field to java.lang.Integer

痞子三分冷 提交于 2019-11-30 16:40:07
问题 User declaration: @Entity public class User { @Id @GeneratedValue private Integer id; .... Pattern declaration: @Entity public class Pattern { @Id @GeneratedValue Integer id; ... UserPatternDeclaration: public class UserPattern { @Id @GeneratedValue Integer id; @ManyToOne @JoinColumn(name = "user_id") User user; @ManyToOne @JoinColumn(name = "pattern_id") Pattern pattern; ... request to database: Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("from

Externalize credentials from persistence.xml in J2SE app

耗尽温柔 提交于 2019-11-30 15:39:00
I'm writing a J2SE app (no enterprise container) that uses JPA for persistence. Here is my persistence.xml : <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="dbstats"> <!-- TODO: why is this needed? --> <class>dreambear.stats.data.GamePlayedEvent</class> <class>dreambear.stats.data.HyveMemberCountPoll</class> <class>dreambear.stats.data.ProfileCountPoll</class> <class

Use of joinTransaction in JPA

六眼飞鱼酱① 提交于 2019-11-30 15:32:41
The following code is from JPA specs. I could not understand why em.joinTransaction() is required in createLineItem(int quantity) . Can anyone provide an apt explanation? @Stateful public class ShoppingCartImpl implements ShoppingCart { @PersistenceUnit private EntityManagerFactory emf; private EntityManager em; private Order order; private Product product; @PostConstruct public void init() { em = emf.createEntityManager(); } public void initOrder(Long id) { order = em.find(Order.class, id); } public void initProduct(String name) { product = (Product) em .createQuery("select p from Product p

ORM or something to handle SQL tables with an order column efficiently

旧街凉风 提交于 2019-11-30 15:06:46
I got an Java application using SQL tables that contains an ordered list of entities, ordered by an order column. I would like to add/remove things in/from the middle of the list. Now, I'm wondering if some persistence framework / orm / you-name-it could provide this kind of functionality with batch update of order column. At the basic case Hibernate (and probably others also) provide this functionality. The problem is that the objects are handled one at time, which becomes problem when the list is large enough. Alternate solution would be to do the thing with a batch SQL update, like the

StaleStateException when saving entity with complex relations

谁说胖子不能爱 提交于 2019-11-30 15:01:01
The hibernate entity I am saving in the database (Oracle) has very complex relations, in the sense that it has many related entities. It looks something like this... @Table(name = "t_HOP_CommonContract") public class Contract { @Id private ContractPK id; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @PrimaryKeyJoinColumn private ContractGroupMember contractGroupMember; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = "TransactionId", referencedColumnName = "TransactionId"), @JoinColumn(name = "PrimaryContractId",

Entity Framework won't persist data in SQL Express (MDF)

喜欢而已 提交于 2019-11-30 15:00:45
问题 I was developing an application using Entity Framework and storing data in a .mdf database. My code can read the data, apparently it can save too, but only apparently. It get no erros, while the program is running it act like the data was saved, I can for example save an object, dispose the context, create a new one, and then when I search my object it's there! But when I query the database to see the stored data there's nothing there. If I close the app and run it again, all data is gone.

Changing the type of an entity preserving its ID

两盒软妹~` 提交于 2019-11-30 14:58:51
问题 I am using hibernate as a persistence layer. There are 2 entities that live in the same table extending one superclass with single table inheritance strategy. @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class A { @Id @GeneratedValue protected Long id; // some common fields for B and C } @Entity public class B extends A { // B-specific fields } @Entity public class C extends A { // C-specific fields } I have an instance of B with id=4. How do I change the type

Hibernate persist failure with PostGIS Geometry

五迷三道 提交于 2019-11-30 14:06:32
问题 Related to previous question. I have a Spring Roo application using Hibernate to write a Geometry object to a PostGIS database using JTS. I believe I've fixed the problems I had in defining my Geometry object, and now Hibernate is executing its persist() method, but something is going wrong just before it hits the DB and I'm getting the exception below. Here are some interesting lines. First from the Hibernate logs, the object to be persisted, and then an SQL query (presumably the ? are

How to use Slick's mapped tables with foreign keys?

前提是你 提交于 2019-11-30 13:40:37
I'm struggling with Slick's lifted embedding and mapped tables. The API feels strange to me, maybe just because it is structured in a way that's unfamiliar to me. I want to build a Task/Todo-List. There are two entities: Task: Each task has a an optional reference to the next task. That way a linked list is build. The intention is that the user can order the tasks by his priority. This order is represented by the references from task to task. TaskList: Represents a TaskList with a label and a reference to the first Task of the list. case class Task(id: Option[Long], title: String, nextTask: