简体   繁体   English

基于多列唯一约束的Sybase / Hibernate自动增量

[英]Sybase/Hibernate Auto-increment based on multi-column unique constraint

I have a table like this in sybase 我在sybase中有一个这样的表

uuid | varchar

parent_uuid | varchar

entity_version | int

with a composite unique constraint based on parent_uuid and entity_version. 具有基于parent_uuid和Entity_version的复合唯一约束。

I am looking at auto incrementing entity_version based on this constraint. 我正在考虑基于此约束条件自动递增entity_version。 So the first insert for parent_uuid = 'ABC' will be 0 and later inserts will take in value 1,2,3 ... 因此,parent_uuid ='ABC'的第一个插入将为0,以后的插入将取值为1,2,3 ...

We have a hibernate based java application. 我们有一个基于休眠的Java应用程序。 However there are support occurrences where this table could be updated by bypassing hibernate so I would rather use something which could auto increment this value in the db. 但是,在某些情况下,可以通过绕过休眠状态来更新此表,因此我宁愿使用可以自动增加db中该值的方法。

Is there a way outside writing a trigger/ procedure 有没有办法在编写触发器/过程之外

Hibernate is not for mainating the consitency iof its accessed from more than otherw ay too. Hibernate也不是为了维护其从其他地方访问的优势。 Database trigger is the way, but if you have only on/few such requirement. 数据库触发是一种方式,但是如果您只有/很少有这样的要求。 If its peppered in your application. 如果将其添加到您的应用程序中。 You need something else. 您还需要其他东西。 Like Distibuted database or distributed cache only having access to your database. 像Distibuted数据库或分布式缓存一样,只能访问您的数据库。 Lone case, trigger will do. 单独的情况下,触发器将起作用。 And May be a consol/main/web class invoking that trigger from hibernate too just to have a single set of OIRM too there. 而且可能是一个consol / main / web类调用,它也从休眠中触发,只是在那里也只有一组OIRM。 Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM