天道酬勤,学无止境

persistence

JPA @OneToMany and composite PK

问题 我正在做一个 JPA 项目。 我需要在具有三个主键的类上使用 @OneToMany 映射。 您可以在此之后找到错误和类。 javax.persistence.PersistenceException: No Persistence provider for EntityManager named JTA_pacePersistence: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory: javax.persistence.PersistenceException javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException Exception Description: predeploy for PersistenceUnit [JTA

2022-05-09 17:40:09    分类:技术分享    jpa   persistence   primary-key   many-to-one

how to make data structures persistent in c++?

问题 回答1 回答2 通常,您需要对结构进行序列化,以便将其写入文件或数据库。 如果您有自定义结构,那么您将需要编写序列化和反序列化的方法(即在结构中写出和读取)。 否则,如果您使用了库中的结构,则可能已经有(反)序列化方法。 例如。 链表可能会像这样序列化为字符串: [1,2,3,4,5] 回答3 struct S { /* ... */ }; //... ofstream out("temp.aux"); S s; char* c = reinterpret_cast<char*>(&s); out << sizeof(s); for(int i = 0; i < sizeof(s); ++i) { out << c[i]; } out.close(); // ... ifstream in("temp.aux"); int size; in >> size; char* r = new char[size]; for(int i = 0; i < size; ++i) { in >> r[i]; } S* s = reinterpret_cast<S*>(r); in.close();

2022-05-08 03:00:12    分类:技术分享    c++   data-structures   persistence

Persisting std::chrono time_point instances

问题 持久化 std::chrono time_point 实例然后将它们读回相同类型的另一个实例的正确方法是什么? typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t; time_point_t tp = std::chrono::high_resolution_clock::now(); serializer.write(tp); . . . time_point_t another_tp; serializer.read(another_tp); 对 write/read 的调用假设 time_point_t 类型的实例可以以某种方式转换为字节表示,然后可以将其写入磁盘或套接字等或从其读取。 Alf 建议的可能解决方案如下: std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now(); //Generate POD to write to disk unsigned long long ns0 = t0.time_since_epoch().count(); //Read POD from disk and attempt to

2022-05-07 12:04:16    分类:技术分享    c++   serialization   c++11   persistence   chrono

Persisting complex test data

问题 我们正在使用构建器模式来生成测试数据。 这些领域对象之间有关系。 我们的功能测试要求这些对象被持久化。 想想这个模型: 如果我想要一个普通的 CI 实例,请执行aNew().c().build() 如果我想让它持久化,我会执行aNew().c().saveIn(session) 如果我想要一个具有已知 BI 的 C 实例,请执行aNew().c().with(b).build() 嗯,你明白了。 我的问题是,如果我想坚持一个C,它应该坚持它是B吗? 还是应该事先坚持? 如果我想要一个合理的默认 B 怎么办? 如果我想坚持 D 怎么办? 它应该坚持所有A,B,C吗? 当然,真实系统要复杂得多(有时带有循环引用)。 我正在寻找持久化复杂测试数据的最佳实践。 编辑:看来我遇到了语言障碍,我的母语不是英语,所以我很抱歉晦涩难懂。 以下是更多信息: 我要测试的不是遗留代码我正在尝试编写覆盖测试,而不是单元测试(因此我不会嘲笑任何东西) 如果数据库被填充到一定程度(它不使用所有实体),我试图测试的软件就可以工作。 PS。 请不要犹豫,询问更多信息,因为我一直在努力寻找可能的最佳实践。 我想出的最接近的事情是: 在构建实体时跟踪明确设置的内容。 假设显式设置的实体已经被持久化,不要持久化它们。 坚持其他一切(使用他们自己的坚持者)。 这会起作用,但是我的蜘蛛感觉很刺痛,我认为我做错了什么

2022-05-04 23:45:04    分类:技术分享    testing   persistence   fluent-interface   test-data

Configuring persistence and orm with JPA 2

问题 我在我的 jBPM 项目中使用 Persistence 时遇到了一些麻烦。 我的配置是 jBPM 5.4 + Hibernate + JPA 2,我目前正在设置流程以通过 persistence.xml 连接到具有持久性的数据库。 我只是尝试将默认数据源(在 H2 服务器中)与我的自定义 persistence.xml 连接,但我一遍又一遍地收到相同的错误: Unknown entity: org.jbpm.persistence.processinstance.ProcessInstanceInfo 我已手动将以下内容添加到我的 src/META-INF 文件夹 JBPMorm-JPA2.xml 中,但错误仍然存​​在。 谁能帮我? JBPMorm-JPA2.xml: <?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd" version="2.0">

2022-05-04 16:04:35    分类:技术分享    hibernate   persistence   jpa-2.0   jbpm

Persisting complex test data

We are using builder pattern to generate test data. These domain objects have relations between them. Our functional tests require these objects to be persisted. Think about this model: If I want a plain instance of C I do aNew().c().build() If I want it to be persisted I do aNew().c().saveIn(session) If I want an instance of C with a known B I do aNew().c().with(b).build() Well, you got the idea. My problem is, if I want to persist a C, should it persist it's B? Or should it be persisted before hand? What about if I want a reasonable default B? What about if I want to persist a D? Should it

2022-05-02 06:46:18    分类:问答    testing   persistence   fluent-interface   test-data

Setting a JPA timestamp column to be generated by the database?

In my SQL Server 2000 database, I have a timestamp (in function not in data type) column of type DATETIME named lastTouched set to getdate() as its default value/binding. I am using the Netbeans 6.5 generated JPA entity classes, and have this in my code @Basic(optional = false) @Column(name = "LastTouched") @Temporal(TemporalType.TIMESTAMP) private Date lastTouched; However when I try to put the object into the database I get, javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.generic.Stuff.lastTouched I've

2022-05-01 20:19:32    分类:问答    java   jpa   persistence   annotations   timestamp

Mybatis 3.0.5 nested collection mapping Example

I am investigating the mapping facilities of MyBatis 3.0.5. The database is H2 (1.3.160) in running embedded mode. With the help of the user manual, I got the straightforward parts working. But I am having a hard time mapping a Set that uses a HashMap as the backing storage. Here's the Java code for the custom collection that has the custom set as field (simplified for brevity) public class CustomCollection { @JsonProperty private CustomSet<CustomItem> customItems; public CustomCollection() { customItems = new CustomSet<CustomItem>(); } // other stuff } Here's the CustomSet code (again

2022-05-01 02:16:54    分类:问答    java   collections   mapping   persistence   MyBatis

react-native-image-picker - persistent storage after rebuild

I've been hitting my head on the screen for some time and just can't get it to work despite all the information I've found on git or stackoverflow. What I'm trying to achieve: Persistence of the images selected (from library or camera). Persistence also when I rebuild my app, which means when I run react-native run-ios for iOS, or react-native run-android for Android. What I've implemented Here is my function that is called when I add an image. ImagePicker.showImagePicker({ storageOptions: { path: 'myCustomPath', waitUntilSaved: true, cameraRoll: true, skipBackup : true }, noData: true }, res

2022-04-30 14:40:28    分类:问答    ios   react-native   persistence   react-native-image-picker

NonUniqueObjectException when persist object

I am getting NonUniqueObjectException when i persist an object using JPA. The object where i make persisent, have other objects and in some cases the objects have the same id. Make a merge in object where is already saved in DB is a possibility but i only can make persist at one object (this object have all information) I can put any annotation on my id to make a merge when this id is already saved in MySQL database?

2022-04-29 15:20:35    分类:问答    java   mysql   hibernate   persistence