问题标签 [persistence]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
6 回答
27298 浏览

java - 在 Java 中生成全局唯一标识符

简介:我正在开发一个持久化的 Java Web 应用程序,我需要确保我持久化的所有资源都具有全局唯一标识符,以防止重复。

精美的印刷品:

  1. 我没有使用 RDBMS,所以我没有任何花哨的序列生成器(比如 Oracle 提供的那个)
  2. 我希望它很快,最好全部在内存中 - 我宁愿不必打开文件并增加一些值
  3. 它需要是线程安全的(我预计一次只有一个 JVM 需要生成 ID)
  4. JVM 实例之间需要保持一致性。如果服务器关闭并启动,ID 生成器不应重新生成它在先前实例化中生成的相同 ID(或者至少机会必须非常非常渺茫 - 我预计会有数百万的预置资源)
  5. 我已经看过 EJB 唯一 ID 模式文章中的示例。它们对我不起作用(我宁愿不完全依赖 System.currentTimeMillis() ,因为我们将每毫秒保留多个资源)。
  6. 我已经查看了这个问题中提出的答案。我对他们的担忧是,随着时间的推移,我获得重复 ID 的可能性有多大?我对使用java.util.UUID作为UUID的建议很感兴趣,但同样,重复的机会需要非常小。
  7. 我正在使用JDK6
0 投票
2 回答
2036 浏览

c++ - 如何使用数据访问对象进行序列化和关系数据库数据访问

我正在开发一个 C++ 域模型类库,它应该提供一些设施或框架(即接口类等),用于向二进制文件和 RDBMS 写入/读取类实例数据。这个库的基础是一个使用 RDBMS 的应用程序,并且有几个方法通过执行一系列数据库检索和更新调用来获取成员数据的集合来实例化一个类。序列化数据访问具有不同的数据组织方式,因此我希望域模型完全不知道主键/外键、ID 等。

为了解决这个问题,我考虑使用数据访问对象(DAO) 模式,并希望对 DAO 对象的“粒度”、生命周期和使用提供一些建议(在您的回复中,请注意我将使用 C++ ,而不是 Java,并且域类不能保存来自 RDBMS 或二进制文件存储的任何 ID/密钥信息):

  1. 域对象的每个 Foo 实例是否都有自己的 FooDAO 实例,或者 Foo 类的所有实例是否都有一个 FooDAO 实例?
  2. FooDAO 是为每个 Foo 实例创建一次,还是仅在需要访问数据时才创建 FooDAO 实例,然后立即销毁?
  3. DAO 上的J2EE页面除了 DAO 之外还引入了 DTO。为什么 DAO 不能传输数据?
  4. 对于具有其他域类 Bar 的实例的复杂域类 Foo,FooDAO 类似乎不可避免地使用 BarDAO 类来检索数据。这将导致域类结构和 DAO 类结构中的并行层次结构/依赖关系。如何最好地管理它?

谢谢你的帮助!

0 投票
5 回答
1252 浏览

linq - Persistence framework?

I'm trying to decide on the best strategy for accessing the database. I understand that this is a generic question and there's no a single good answer, but I will provide some guidelines on what I'm looking for. The last few years we have been using our own persistence framework, that although limited has served as well. However it needs some major improvements and I'm wondering if I should go that way or use one of the existing frameworks. The criteria that I'm looking for, in order of importance are:

  1. Client code should work with clean objects, width no database knowledge. When using our custom framework the client code looks like:

    SessionManager session = new SessionManager(); Order order = session.CreateEntity(); order.Date = DateTime.Now; // Set other properties OrderDetail detail = order.AddOrderDetail(); detail.Product = product; // Other properties

    // Commit all changes now session.Commit();

  2. Should as simple as possible and not "too flexible". We need a single way to do most things.

  3. Should have good support for object-oriented programming. Should handle one-to-many and many-to-many relations, should handle inheritance, support for lazy loading.
  4. Configuration is preferred to be XML based.

With my current knowledge I see these options:

  1. Improve our current framework - Problem is that it needs a good deal of effort.
  2. ADO.NET Entity Framework - Don't have a good understanding, but seems too complicated and has bad reviews.
  3. LINQ to SQL - Does not have good handling of object-oriented practices.
  4. nHibernate - Seems a good option, but some users report too many archaic errors.
  5. SubSonic - From a short introduction, it seems too flexible. I do not want that.

What will you suggest?

EDIT:

Thank you Craig for the elaborate answer. I think it will help more if I give more details about our custom framework. I'm looking for something similar. This is how our custom framework works:

  1. It is based on DataSets, so the first thing you do is configure the DataSets and write queries you need there.
  2. You create a XML configuration file that specifies how DataSet tables map to objects and also specify associations between them (support for all types of associations). 3.A custom tool parse the XML configuration and generate the necessary code. 4.Generated classes inherit from a common base class.

To be compatible with our framework the database must meet these criteria:

  1. Each table should have a single column as primary key.
  2. All tables must have a primary key of the same data type generated on the client.
  3. To handle inheritance only single table inheritance is supported. Also the XML file, almost always offers a single way to achieve something.

What we want to support now is:

  • Remove the dependency from DataSets. SQL code should be generated automatically but the framework should NOT generate the schema. I want to manually control the DB schema.
  • More robust support for inheritance hierarchies.
  • Optional integration with LINQ.

I hope it is clearer now what I'm looking for.

0 投票
3 回答
1939 浏览

java - 在类中存储图像/声音的最佳方式?

我正在开发一种应用程序实例之间的交换格式,以便用户可以将信息保存到文件并稍后恢复。整个“交换格式”是一个被序列化并写入磁盘的类。

您建议如何在该类中存储图形/声音信息?我想避免只是将文件放入 .jar 中。

0 投票
3 回答
739 浏览

linq - 基于 LINQ to SQL 的面向对象模型

我正在使用 LINQ to SQL 进行一些尝试,总体而言,它比 Microsoft 之前的选择(DataSet)要好得多,但面向对象的功能似乎仍然有限。由于我们目前使用在 DataSet 之上创建 OO 模型的自定义持久性框架,因此我希望将该框架移植到新版本,在 LINQ to SQL 之上构建 OO 模型。

  1. 首先,还有其他类似的举措吗?
  2. 其次,你认为这样走是个好主意吗?
0 投票
3 回答
59262 浏览

java - 我必须关闭()每个 EntityManager 吗?

我刚刚开始将我自己开发的持久性框架迁移到 JPA。

鉴于持久性框架隐藏了很多管道,我很想知道不关闭 EntityManagers 是否会造成资源泄漏,或者框架是否会为我收集并关闭它们。

我打算在所有地方关闭它们,但我必须这样做吗?

目前使用 TopLink,只是因为它很容易与 NetBeans 一起工作,但很高兴研究其他 JPA 提供程序。

0 投票
3 回答
950 浏览

ruby - 对象流行度(Prevayler、Madeleine)是否已在生产系统中使用?

对象流行机制是否已在实际生产系统中使用?我指的是像PrevaylerMadeleine这样的东西

我发现的唯一东西是Instiki,一个 wiki 引擎。但自从他们开始他们已经切换到 SQLite。(实际的instiki页面已关闭)

0 投票
3 回答
15020 浏览

c++ - C++ 的 YAML 序列化库?

YAML 似乎是配置文件和数据绑定持久对象的一种很好的格式,以人类可读的形式......

是否有处理 YAML 的 C++ 库?Boost::Serialization 是否有 YAML 选项的计划?

编辑:我更喜欢 OO 库。

0 投票
2 回答
3595 浏览

hibernate - 在 jboss 4.2.1 中启用 ehcache 统计信息

我已经设置了 hibernate.generate_statistics=true 并且现在需要注册 mbean 以便我可以在 jmx 控制台中看到统计信息。我似乎无处可去,这似乎不应该是一个如此困难的问题。也许我让事情变得过于复杂,但无论如何到目前为止我已经尝试过:

  • 我复制了 EhCacheProvider 并让它实例化了 CacheManager 的扩展版本,该版本重载了 init() 并在初始化后调用了 ManagementService.registerMBeans(...) 。在实际调用 registerMBeans(...) 之前,代码都运行良好,这将导致提供程序初始化失败并出现一般错误(不幸的是我没有写下来。)这种方法的动机是this liferay中使用的方法性能演练。
  • 我使用 start 方法创建了自己的 MBean,该方法运行与注册 ehcache 的 jmx mbeans 的示例类似的代码。一切似乎都正常工作,我的 mbean 出现在 jmx 控制台中,但 net.sf.ehcache 没有。
  • 我已经将ehcache升级到1.5(我们使用的是1.3,不确定这是特定于jboss 4.2.1还是我们自己选择的东西)并改为使用SingletonEhCacheProvider并尝试手动获取统计信息而不是处理mbean 注册。但它并没有真正变得更好。如果我调用 getInstance(),则返回的 CacheManager 仅具有 StandardQueryCache 的副本,但 jboss 日志显示许多其他缓存已被初始化(一个用于我们应用程序中的每个缓存实体。)

编辑:嗯,我已经想通了一件事......通过 JConsole 连接确实揭示了统计数据 mbean。我猜 ManagementFactory.getPlatformMBeanServer() 并没有为您提供与 jboss 使用的相同的 mbean 服务器。无论如何,看起来我遇到了与尝试手动收集统计信息时类似的问题,因为即使在单击我的应用程序一段时间后我也得到了全零。

0 投票
5 回答
32487 浏览

nhibernate - 如何使用 NHibernate 持久化枚举

有没有办法使用 NHibernate 将枚举持久化到数据库?那就是有一个包含代码和枚举中每个值的名称的表。

我想保留没有实体的枚举,但仍然有一个从所有其他引用实体到枚举表的外键(枚举的 int 表示)。