persistence

entityManager.getTransaction().rollback() detaches entities?

谁说胖子不能爱 提交于 2019-12-31 02:06:30
问题 I have the following piece of code: EntityManagerFactory emf = Persistence.createEntityManagerFactory("test") EntityManager entityManager = emf.createEntityManager() User user = entityManager.find(User.class, 0); entityManager.getTransaction().begin(); entityManager.getTransaction().rollback(); entityManager.refresh(user); This throws an IllegalArgumentException on the fourth line saying "Entity not managed". If I change the third line to .commit() instead of .rollback() , everything seems to

Entity state and entity id value in JPA/Hibernate after rollback

巧了我就是萌 提交于 2019-12-30 10:52:51
问题 What happens with Entities in session if I make rollback ? Do they get back to the state before transaction ? In particular do they get new ids ? Example: session.startTransaction(); Entity e = new Entity(); //e.id == null session.save (e); //suppose it was ok session.rollback(); // e.id == ??? Update : I've made the Hibernate 4 test. After the test the entity has become a new id. 回答1: I will simply quote from the JPA implementation (3.3.2 Transaction Rollback): For both transaction-scoped

Persisting hashlib state

一个人想着一个人 提交于 2019-12-30 10:13:07
问题 I'd like to create a hashlib instance, update() it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to update() it. Finally, I'd like to get the hexdigest() of the total cumulative run of data. State persistence has to survive across multiple runs. Example: import hashlib m = hashlib.sha1() m.update('one') m.update('two') # somehow, persist the state of m here #later, possibly in another process # recreate m from the persisted

Should the EnumDataTypeAttribute work correctly in .NET 4.0 using Entity Framework?

时光怂恿深爱的人放手 提交于 2019-12-30 07:24:22
问题 I have an enumeration which I'd like to persist as a value of some sort into the underlying database so that I can bring it back and forth. I have read some articles that suggest to create a enumeration wrapper with static implicit operators defined, mapped using a ComplexType object mapping as described in the link below. How to fake Enums in EF4 This solution works flawlessly! My thanks to Alex James. Aside, I discovered of the EnumDataTypeAttribute Class which purpose seems to handle enums

Persistent Objects in Windows XP/Delphi 7

我的未来我决定 提交于 2019-12-30 06:56:07
问题 I am trying to make an AlarmSystem in Delphi 7, Windows XP. I have to register alarms in a Database (MS SQL Server 2000). But what if the server is down??? Well, I can imagine that I have to persist objects of TAlarm type. So, how can I do this? Maybe inheriting from TComponent??? Please, how can I do this?? Thanks a lot. I am sorry about my English. Here you have more info... TAlarm is a class that descends from TObject, basically. There are 10 more classes that descend from TAlarm (some

PHP MySQL connection persistence

半世苍凉 提交于 2019-12-30 06:28:08
问题 I've read a ton about persistent database connections between PHP and MySQL (mysql_connect vs. mysql_pconnect). Same with PDO and MySQLi. It's definitely just my lack of understanding on this one, but how can a database connection be persistent between webpages? In this code: $conn = mysql_pconnect( $server , $user, $pass ); mysql_select_db( $dbname ); If two users load this page at the same time, with two different $dbname variables, will PHP only make one connection to the database or two?

Can NHibernate persist to flat files instead of database?

亡梦爱人 提交于 2019-12-30 06:16:16
问题 Here is a curiousity question. I have an application that must support both flat files and the database as a place to persist data. I was thinking maybe using a .csv or tab-delimited set of files as input ... Is it possible to use NHibernate to write to do both persistance tasks? 回答1: Try using the Jet engine (see this) Dialect and other nhibernate settings should be the ones for Microsoft Access. 回答2: No not to the best of my knowledge. I have the same requirement and have ended up just

StaleStateException when saving entity with complex relations

妖精的绣舞 提交于 2019-12-30 04:59:11
问题 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

Using HSQL in-memory database as JPA datasource

a 夏天 提交于 2019-12-30 03:42:27
问题 I have an in-memory data source: java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", ""); emf = Persistence.createEntityManagerFactory("manager"); But now I'm stuck. I want to use it as a JPA data source in a J2SE application. I've scoured the entire web but all info is related to J2EE. <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

Persisting 3rd party objects with JPA

心已入冬 提交于 2019-12-30 03:23:10
问题 In my current project I am using a 3rd party library which has no JPA annotations. How can I persist objects from that library using JPA and external mappings? 回答1: Check this and this. In short: Create META-INF/orm.xml Follow (read) the .xsd You don't have to manually map each column - only some specifics (i.e. collections and the id) are required. All fields are assumed to be columns (if the class is mapped). If there are no collections, something like this suffices: <?xml version="1.0"