标签: uuid

在JPA/hibernate中映射UUID的问题

根据文档,hibernate 3.6应该支持java.util.UUID类型.但是当我将其映射为:

@Id protected UUID uuid;
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [test-applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    ... …
Run Code Online (Sandbox Code Playgroud)

java uuid hibernate jpa

27
推荐指数
4
解决办法
5万
查看次数

如何将UUID更改为字符串?

我需要能够为用户分配UUID并将其记录在.txt文件中.这就是我的全部:

import uuid
def main():
    a=input("What's your name?")
    print (uuid.uuid1())
    f.open(#file.txt)
main()
Run Code Online (Sandbox Code Playgroud)

我试过了:

f.write(uuid.uuid1())
Run Code Online (Sandbox Code Playgroud)

但没有出现,可能是一个逻辑错误,但我不知道.

python string uuid

27
推荐指数
2
解决办法
4万
查看次数

GUID到ByteArray

我刚刚编写了这段代码,将GUID转换为字节数组.任何人都可以在其中拍摄任何漏洞或建议更好的东西?

 public static byte[] getGuidAsByteArray(){

 UUID uuid = UUID.randomUUID();
 long longOne = uuid.getMostSignificantBits();
 long longTwo = uuid.getLeastSignificantBits();

 return new byte[] {
      (byte)(longOne >>> 56),
      (byte)(longOne >>> 48),
      (byte)(longOne >>> 40),
      (byte)(longOne >>> 32),   
      (byte)(longOne >>> 24),
      (byte)(longOne >>> 16),
      (byte)(longOne >>> 8),
      (byte) longOne,
      (byte)(longTwo >>> 56),
      (byte)(longTwo >>> 48),
      (byte)(longTwo >>> 40),
      (byte)(longTwo >>> 32),   
      (byte)(longTwo >>> 24),
      (byte)(longTwo >>> 16),
      (byte)(longTwo >>> 8),
      (byte) longTwo
       };
}
Run Code Online (Sandbox Code Playgroud)

在C++中,我记得能够做到这一点,但我想在内存管理方面没有办法在Java中做到这一点吗?:

    UUID uuid = UUID.randomUUID();

    long[] longArray = new long[2];
    longArray[0] …
Run Code Online (Sandbox Code Playgroud)

java uuid guid bytearray

26
推荐指数
2
解决办法
2万
查看次数

使用JPA在PostgreSQL中保留UUID

我试图在PostgreSQL中持久化一个使用UUID作为主键的实体.我已经尝试将其作为简单的UUID持久化:

@Id
@Column(name = "customer_id")
private UUID id;
Run Code Online (Sandbox Code Playgroud)

有了上面的内容,我收到了这个错误:

ERROR: column "customer_id" is of type uuid but expression is of type bytea
Hint: You will need to rewrite or cast the expression.
Position: 137
Run Code Online (Sandbox Code Playgroud)

我也尝试将UUID作为byte []保持无效:

@Transient
private UUID id;

@Id
@Column(name = "customer_id")
@Access(AccessType.PROPERTY)
@Lob
protected byte[] getRowId() {
    return id.toString().getBytes();
}

protected void setRowId(byte[] rowId) {
    id = UUID.fromString(new String(rowId));
}
Run Code Online (Sandbox Code Playgroud)

如果我删除@Lob,我得到的错误与上面发布的错误相同.但是应用@Lob后,错误会略有变化:

ERROR: column "customer_id" is of type uuid but expression is of type bigint
Hint: You will …
Run Code Online (Sandbox Code Playgroud)

java postgresql uuid hibernate jpa

25
推荐指数
3
解决办法
3万
查看次数

Cassandra:生成一个唯一的ID?

我正在研究分布式数据库.我试图生成一个唯一的ID将作为列族主键.

我阅读了一些关于使用Java进行此操作的文章,UUID但似乎存在碰撞的可能性(即使它非常低).

我想知道是否有办法根据时间生成一个唯一的ID?

uuid cql cassandra cql3

25
推荐指数
3
解决办法
3万
查看次数

Oracle的SYS_GUID()UUID RFC 4122是否兼容?

我想知道Oracle的SYS_GUID()函数是否返回符合RFC 4122的UUID.例如:

SQL> select sys_guid() from dual;

SYS_GUID()
--------------------------------
A6C1BD5167C366C6E04400144FD25BA0
Run Code Online (Sandbox Code Playgroud)

我知道,SYS_GUID()返回一个16字节的RAW数据类型.Oracle使用RAWTOHEX()和可能TO_CHAR()打印出上面的ID.将其解释为符合UUID的字符串格式是否正确:

A6C1BD51-67C3-66C6-E044-00144FD25BA0
Run Code Online (Sandbox Code Playgroud)

我认为它不符合RFC 4122标准,因为定义说,有效的UUID必须在UUID本身内命名UUID-Version.

符合RFC 4122的UUID(版本3)的语法:

xxxxxxxx-xxxx-3xxx-xxxx-xxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)

oracle uuid rfc

24
推荐指数
2
解决办法
2万
查看次数

UUID生成的字符类型

  1. java.util.UUID中产生的特殊字符?
  2. UUID生成的每个字符的类型(例如 - 大写,小写,数字)是什么.

java uuid

24
推荐指数
3
解决办法
2万
查看次数

UUID.randomUUID()是否适合用作一次性密码?

正如前面所讨论的,确认电子邮件应该有一个独特的,(几乎)未猜测的代码-基本上是一个一次性密码 --in确认链接.

UUID.randomUUID()文档说:

使用加密强伪随机数生成器生成UUID.

这是否意味着正确实现的JVM中的UUID随机生成器适合用作唯一的(实际上)不可猜测的OTP?

java security random uuid

24
推荐指数
3
解决办法
2万
查看次数

插入和选择UUID为二进制(16)

我不明白为什么

SELECT UUID();
Run Code Online (Sandbox Code Playgroud)

返回类似于:

3f06af63-a93c-11e4-9797-00505690773f
Run Code Online (Sandbox Code Playgroud)

但是如果我将它插入二进制(16)字段(UUID()函数)并使用例如BEFORE INSERT触发器并运行select,它将返回如下内容:

0782ef48-a439-11
Run Code Online (Sandbox Code Playgroud)

请注意,这两个UUID不是相同的数据.

我意识到二进制文件和一个UUID字符串看起来不一样,但是所选数据不应该只有那么长吗?否则,它怎么可能同样具有独特性呢?

将它存储为char(36)更好吗?我只需要它是唯一的,以防止重复插入.它永远不会被选中或用于连接.

编辑:

在触发之前会是这样的:

BEGIN

if NEW.UUID IS NULL THEN

NEW.UUID = UUID();

END IF

END
Run Code Online (Sandbox Code Playgroud)

mysql binary uuid

24
推荐指数
5
解决办法
4万
查看次数

Postgres中的UUID主键,什么插入性能影响?

我想知道在PosgreSQL中使用非顺序UUID作为表中主键的性能影响.

在使用集群存储来存储表记录的DBMS中,一旦表太大,使用UUID会增加插入成本,因为必须从磁盘读取以查找要执行插入的数据页.留在记忆中.据我了解,Postgres不会在插入上维护行聚类,所以我想在Postgres中使用UUID PK不会损害该插入的性能.

但我认为它会使插入到索引中的主键约束一旦表很大就会变得更加昂贵,因为它必须不断地从磁盘读取以在插入新数据时更新索引.而使用顺序键,索引只会在尖端更新,而尖端始终在内存中.

假设我正确理解了对索引的性能影响,有没有办法解决这个问题,或者UUID在一个大的,未分区的表上是不是一个好的PK?

database postgresql indexing performance uuid

23
推荐指数
2
解决办法
9089
查看次数