标签: embeddable

Embeddable和ElementCollection嵌套

我有一个相当典型的场景,其中有一个主要的@Entity,并且他内部的所有内容都是可嵌入的(因此没有父级内部的所有内容都没有意义).现在JPA 2.0阻止我将@ElementCollection嵌套在另一个@ElementCollection中定义的@Embeddable中:

JSR-317 2.6可嵌入类和基本类型的集合元素集合中包含的可嵌入类(包括另一个可嵌入类中的可嵌入类)不能包含元素集合,也不能包含与实体之外的实体的关系.多对一或一对一的关系

现在的问题是:这是为什么?一个简单的例子:

@Entity
public class Tournament {
    @Id
    Long id;

    @ElementCollection
    @CollectionTable
    private List<Edition>;
}

@Embeddable
public class Edition {

    @ElementCollection
    @CollectionTable
    private List<Round>
}

@Embeddable
public class Round {

    blabla;
}
Run Code Online (Sandbox Code Playgroud)

这有什么问题?这只是一个例子,您可以将Round和Edition定义为Entity并解决问题,但在我的情况下,出于多种原因,我需要强制执行非嵌套的东西没有他的父级是没有意义的.

为什么JPA 2.0必须阻止我这样做?

java hibernate jpa embeddable

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

Youtube视频不可嵌入,但API表示它是

我想检测视频是否可以在Youtube外部播放。我目前正在检测版权侵权,可嵌入和“可合成”的限制。我用这些调用两次API,一次在版本3中,一次在版本2中:

http://gdata.youtube.com/feeds/api/videos/{videoId}?v=2&alt=jsonc

https://www.googleapis.com/youtube/v3/videos?id={videoId}&key={key}&part=status
Run Code Online (Sandbox Code Playgroud)

对于视频(https://www.youtube.com/watch?v=TzmyOT1kcfc),我得到了以下答案:

{

    "kind": "youtube#videoListResponse",
    "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/yoB7kT2xS4cnv1zDF-EiUrfidKQ\"",
    "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
    },
    "items": [
        {
            "kind": "youtube#video",
            "etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/mk9sFeT7lpR0qthcrYeJssWlayY\"",
            "id": "TzmyOT1kcfc",
            "status": {
                 "uploadStatus": "processed",
                 "privacyStatus": "public",
                 "license": "youtube",
                 "embeddable": true,
                 "publicStatsViewable": true
            }
            "player": {
                "embedHtml": "<iframe type='text/html' src='http://www.youtube.com/embed/TzmyOT1kcfc' width='640' height='360' frameborder='0' allowfullscreen='true'/>"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

和:

{
    "apiVersion": "2.1",
    "data": {
        "id": "TzmyOT1kcfc",
        "uploaded": "2014-08-07T11:13:03.000Z",
        "updated": "2014-09-22T01:13:46.000Z",
        "uploader": "topgear",
        "category": "Autos",
        "title": "Aston Martin: DBS vs DB9 and Vanquish (HQ) - …
Run Code Online (Sandbox Code Playgroud)

youtube video youtube-api embeddable

5
推荐指数
1
解决办法
599
查看次数

在EclipseLink-2.5.2中为Embeddable类配置ID类型时出现奇怪的问题

在我当前的实现中,我为每个db表都有单独的实体类.我正在使用JPA和eclipselink-2.5.2.这对我来说很好,但在某些时候,当数据很大时,它会滞后.这就是我决定开始使用@ Embedded,@ Embeddable和@EmbeddedId的原因.在这样做时,我收到的错误对我来说非常奇怪.这是完整的堆栈跟踪:https://gist.githubusercontent.com/tjDudhatra/b955812e0d1a71cf97f1/raw/11ea458869e24baae744530417ac99bc877ed514/gistfile1.txt

具体,让我给你一个确切的场景,在这种情况下,我得到了例外.考虑这个有三个类的Code块.一个注释为@Entity,其他两个注释为@Embeddable.我知道在一个类中我们不能定义@Id和@EmbeddedId而我没有这样做,那么在部署服务器时,我得到的异常只表示:

[class org.apache.{SomeClass}]同时包含@EmbdeddedId(在属性[id]上)和@Id(在属性[]上.两种ID类型都不能在同一实体上指定.

@Entity
@Table(name="user")  
public class User {

  @ID
  public Long id;

  @Column(name="userCode")
  public String userCode;

  @ElementCollection
  @CollectionTable(name = "address", joinColumns = @JoinColumn(name = "user_id"))
  public List<Address> addressList;

  ....
}

@Embeddable  
public class Address {

  @EmbeddedId
  @Column(name = "id")
  public Long id;

  @Column(name="userId")
  public Long userId;

  @Column(name="address-line-1")
  public String addressLine1;

  @Column(name="address-line-2")
  public String addressLine2;

  @ElementCollection
  @CollectionTable(name = "phone", joinColumns = @JoinColumn(name = "user_id"))
  protected List<Phone> phoneList;

  ....
}

@Embeddable 
public class Phone { …
Run Code Online (Sandbox Code Playgroud)

java jpa eclipselink embeddable

5
推荐指数
1
解决办法
318
查看次数

Nullable embedded value object with not nullable fields

I created an entity "Person" in Doctrine2, and I added to it an Adress entity, which is a value object (embeddable).

I want to allow a Person creation, without an Address, so I tag my embedded as "nullable = true". But on the other hand, my Address entity, if it exists, SHOULD contains at least some information (like city, zip code, etc...). So it has "nullable = false" attributes.

Address:
    type: embeddable
    fields:
        [...]
        city:
            type: string
            length: 255
            nullable: …
Run Code Online (Sandbox Code Playgroud)

nullable embeddable symfony doctrine-orm

5
推荐指数
0
解决办法
1296
查看次数

EmbeddedId 上的 JPA 标准和谓词

我有点麻烦。我正在使用 JPA Criteria 进行动态选择(使用标准作为 where 子句具有可选变量...)但我的实体之一具有 EmbeddedId ,其中包含其中的用户列并且需要检查用户 ID...

这是我的实体。

@Entity
@Table(name = "user_like") 
public class UserLike extends AbstractTimestampEntity implements Serializable {

  @EmbeddedId
   private UserLike.userLikePK userLikePK= new UserLike.UserLikePK();
   ...
   with all the setter and gets
   ...

   @Embeddable
   public static class UserLike implements Serializable{
      @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
      @JoinColumn(name = "user_id")
      private User user;

      ... (and an other column, not important for now=
   }   
}
Run Code Online (Sandbox Code Playgroud)

用户是包含列 userId 的其他实体

现在这就是我的查询的样子。

Root<Poi> p = cq.from(Poi.class);
Join<Poi,UserLike> ul = p.join("userLike");


 List<Predicate> predicates …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa criteria embeddable

4
推荐指数
1
解决办法
3192
查看次数

@Embeddable 和 @ManyToOne

想象一下接下来的课程

@Embeddable
class A {
    @ManyToOne
    public B classB;

    ...
    public State someEnum;
}

@Entity
@Table(name = "TEST")
class B {
    public long id;
    //... some data


   @Embedded
   @AttributeOverrides({
        @AttributeOverride(
                name = "classB.id",
                column = @Column(name = "EMBEDDED1_ID")
        ),
        @AttributeOverride(
                name = "someEnum",
                column = @Column(name = "EMBEDDED1_SOMEENUM")
        )
   })
   public A embedded1;

   @Embedded
   @AttributeOverrides({
        @AttributeOverride(
                name = "classB.id",
                column = @Column(name = "EMBEDDED2_ID")
        ),
        @AttributeOverride(
                name = "someEnum",
                column = @Column(name = "EMBEDDED2_SOMEENUM")
        )
   })
   public A embedded2;
} …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa embeddable

4
推荐指数
1
解决办法
2901
查看次数

使用jQuery和ASP.NET MVC嵌入小部件

我需要一些建议,以便在开发可嵌入的小部件时使用最佳方法,我的网站用户可以使用它来在他们的网站上显示我们的内容.

假设我们有一些内容使用jQuery插件进行渲染,我们希望为客户提供一种简单的方法将其嵌入到他们的网站中.

一种选择可能是使用IFrame,但我们知道这是非常具有侵略性并且存在一些问题.我也想知道你对此的看法.

另一种方法可能是给出这样的代码,以显示第23项:

<DIV id="mysitewidget23"><script src="http://example.com/scripts/wdg.js?id=23" /></DIV>
Run Code Online (Sandbox Code Playgroud)

并且以某种方式(需要帮助......)创建wdg.js服务器端脚本以在DIV内部注入内容,jQuery,所需的插件.

这看起来更有希望,因为用户可以在一定程度上定制DIV的样式,并且不需要IFRAME.但是哪个是在ASP.NET MVC中执行此操作的最佳和更有效的方法?

当然还有许多其他方法可以实现我们的需求.

asp.net-mvc jquery widget embeddable

3
推荐指数
1
解决办法
3545
查看次数

开源C或C++嵌入式关系数据库(要部署的复制源)

我有一个跨平台项目,客户端获取代码,但不想解决任何依赖项.使用关系数据库可以最好地解决这些需求,因此我似乎需要将可嵌入关系数据库的源代码复制到我的程序中,并将库直接编译为可执行文件或作为项目的一部分.

是否存在具有许可许可的关系嵌入式数据库,以便我可以将源直接复制到项目中?哪一个代码库最小?理想情况下,我正在考虑一个C源文件和一个标题,我可以将其复制到程序中并立即开始使用.

c c++ database embeddable

3
推荐指数
1
解决办法
972
查看次数

在嵌入对象上使用 CriteriaBuilder

我正在尝试使用@Embeddablewith根据嵌入的属性CriteriaBuilder过滤父项Entity的结果。我使用 Eclipse Link 来生成元数据类。

这是嵌入的类/实体:

@Embeddable
public class Stamp implements Serializable {

   @Basic()
   @Column(name = "stamp_year", nullable = false)
   private int year;
Run Code Online (Sandbox Code Playgroud)

父类具有Stamp作为成员:

@Entity(name = "Message")
public class Message implements Serializable {

   @Embedded
   private Stamp stamp = new Stamp();
Run Code Online (Sandbox Code Playgroud)

现在这段代码应该使用Message基于嵌入类属性年份的类和过滤结果:

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Message> cq = cb.createQuery(Message.class);
    Root<Message> root = cq.from(Message.class);
    Predicate p = cb.conjunction();
    p = ??????
    cq.where(p);
    TypedQuery<Message> tq = em.createQuery(cq);
    List<Message> messages = tq.getResultList();
Run Code Online (Sandbox Code Playgroud)

在第 5 …

jpa eclipselink embeddable metamodel

3
推荐指数
1
解决办法
2641
查看次数

如何在 spring data - jpa -hibernate 中使用复合键进行 findby ?@EmbeddedId

@Embeddable
public class AccountTransactionId implements Serializable {
    private String trxDate;
    private String acctNo;
    private int trxNo;
}

@Entity
public class Transaction {
    @EmbeddedId
    private AccountTransactionId accountTransactionId;

    private int amt;
    private int fee;
    private String cancelYn;
}
Run Code Online (Sandbox Code Playgroud)

这是我的存储库。如何制作find方法?我对此一无所知

List<Map<String, Object>> findByAccountTransactionId_trxDate(String trxDate);
Run Code Online (Sandbox Code Playgroud)

我尝试了“findByAccountTransactionId_trxDate”、“findByAccountTransactionIdTrxDate”、“findByIdTrxDate”...

hibernate jpa composite-key embeddable spring-data

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

@Embeddable 类中的 JPA @Version

当我在 @Embeddable 中使用 JPA @Version 注释时,我得到以下指向我的Updateable类的异常:

org.hibernate.AnnotationException: Unable to define @Version on an embedded class
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

org.hibernate.AnnotationException: Unable to define @Version on an embedded class
Run Code Online (Sandbox Code Playgroud)
@Embeddable
public class Updateable {
    @Version
    private long modcount;

    private String updatedBy;

    private DateTime updatedAt;

    // getters & setters
}
Run Code Online (Sandbox Code Playgroud)

在@Embeddable 中不可能有@Version,还是这个Hibernate 特定的?

java jpa version embeddable

2
推荐指数
1
解决办法
2636
查看次数