首页 \ 问答 \ JPA(休眠)onetomany关系(JPA (hibernate) onetomany relation)

JPA(休眠)onetomany关系(JPA (hibernate) onetomany relation)

我不确定我想要做什么双向onetomany关系(休眠引擎)。 域模型的缩小版本:

class Person {
@OneToMany(mappedBy="personFrom", cascade = CascadeType.PERSIST)
    public List<Relationship> relationships;
}

class Relationship {
@ManyToOne
  public Person personFrom;

  @ManyToOne
  public Person personTo;
}

一些观察结果:
1.使用上面的映射,没有创建连接表。
2.当我删除mappedBy(@OneToMany(cascade = CascadeType.PERSIST))时,创建了连接表,我可以通过Person持久保存。 “personFrom”字段为空,但我认为这是正常的,因为通过连接表维护关系。

我也尝试通过在关系中指定连接列,没有任何区别。 任何帮助,高度赞赏。 谢谢。

编辑:1

根据Dan的评论,如果看到域类的完整内容很重要,我已在下面进行了扩展。

class Relationship extends Model{

  @ManyToOne
  public RelationshipType relationshipType;

  @ManyToOne
  public Person personFrom;

  @ManyToOne
  public Person personTo;

  @ManyToOne
  public Person createdBy;

  @ManyToOne
  public Role roleFrom;

  @ManyToOne
  public Role roleTo;

    @Override
    public String toString() {
        return relationshipType.toString();
    }
}

class Person extends Model {

    public Date dateCreated;

    @Lob
    public String description;

    @OneToMany(cascade = CascadeType.ALL)
    public List<Role> roles;

    @OneToMany(mappedBy="personFrom", cascade = CascadeType.PERSIST)
    public List<Relationship> relationships;
}

角色也与Person有关,但我认为保持personFrom,personTo有助于优化我的查询。

Role extends Model {

    @ManyToOne
    public RoleType roleType;

    @ManyToOne
    public Person createdBy; 
}

I am not sure what I am missing to make a bidirectional onetomany relationship (hibernate engine). A scaled down version of the domain model:

class Person {
@OneToMany(mappedBy="personFrom", cascade = CascadeType.PERSIST)
    public List<Relationship> relationships;
}

class Relationship {
@ManyToOne
  public Person personFrom;

  @ManyToOne
  public Person personTo;
}

Some of the observations:
1. with the above mapping, there is no join table created.
2. When I remove the mappedBy (@OneToMany(cascade = CascadeType.PERSIST) ), the join table is created and i could persist Relationship through Person. "personFrom" field is empty, but I think that is normal as the relation is maintained through the join table.

I also tried by specifying join column at Relationship, didn't make any difference. Any help, highly appreciated. thanks.

Edit:1

As per Dan's comment, if it matters to see the full content of the domain class, I have expanded them below.

class Relationship extends Model{

  @ManyToOne
  public RelationshipType relationshipType;

  @ManyToOne
  public Person personFrom;

  @ManyToOne
  public Person personTo;

  @ManyToOne
  public Person createdBy;

  @ManyToOne
  public Role roleFrom;

  @ManyToOne
  public Role roleTo;

    @Override
    public String toString() {
        return relationshipType.toString();
    }
}

class Person extends Model {

    public Date dateCreated;

    @Lob
    public String description;

    @OneToMany(cascade = CascadeType.ALL)
    public List<Role> roles;

    @OneToMany(mappedBy="personFrom", cascade = CascadeType.PERSIST)
    public List<Relationship> relationships;
}

Role also related to Person, but I think keeping the personFrom, personTo helps to optimize my queries.

Role extends Model {

    @ManyToOne
    public RoleType roleType;

    @ManyToOne
    public Person createdBy; 
}

原文:https://stackoverflow.com/questions/3346154
更新时间:2023-10-24 13:10

最满意答案

我认为你所描述的“iframe”是一个“内容加载项”,它是一个矩形控件而不是幻灯片画布,可以显示你的HTML / JS UI。 今天无法从任务窗格上的按钮插入这些内容。 如果您需要这种“iframe”,只需编写内容加载项:您的用户可以根据需要为每张幻灯片插入此内容加载项的多个实例。

如果您今天需要幻灯片中的任务窗格 Web内容,则需要编写(并发送)两个单独的加载项:一个用于任务窗格“shape”,另一个用于内容“shape”。


I think the "iframe" you're describing is a "content add-in", which is a rectangular control than goes on the slide canvas and can show your HTML/JS UI. It's not possible to insert these from a button on the task pane today. If you need this kind of "iframe", simply write a content add-in: your users can insert as many instances of this content add-in as they want per slide.

If you need a task pane and web content in the slide today, then it's necessary to write (and ship) two separate add-ins: one for the task pane "shape" and the other for the content "shape".

相关问答

更多
  • 在Office Online中测试加载项的推荐方法(在本例中,在PowerPoint Online中是使用Office 365或SharePoint中的加载项“目录”。以下是Office Online调试的说明 。 而且,正如Igaud所指出的,测试的一个原因是并非所有API都存在于两个地方。 另一个原因是Chrome / Firefox / Safari可能会略微改变您的页面,因此确保UI仍然正确非常重要。 The recommended way to test your add-in in Office ...
  • 类ms-dlgTitleBtns的有问题的元素位于托管页面上,而不是在表单本身上; 将自定义脚本/ CSS放在同一页面上可以避免通过iframe修改不同页面上的内容。 您可以将JavaScript / CSS添加到打开对话框的页面,而不是将其添加到表单本身。 (确保在实施更改后正确刷新app.js文件。) The problematic element with the class ms-dlgTitleBtns is located on the hosting page, rather than on ...
  • 我认为你所描述的“iframe”是一个“内容加载项”,它是一个矩形控件而不是幻灯片画布,可以显示你的HTML / JS UI。 今天无法从任务窗格上的按钮插入这些内容。 如果您需要这种“iframe”,只需编写内容加载项:您的用户可以根据需要为每张幻灯片插入此内容加载项的多个实例。 如果您今天需要幻灯片中的任务窗格和 Web内容,则需要编写(并发送)两个单独的加载项:一个用于任务窗格“shape”,另一个用于内容“shape”。 I think the "iframe" you're describing ...
  • 你正在看到预期的行为。 内容加载项在用户切换到幻灯片放映时重新加载。 有一个解决方法。 每次您的加载项导航到新页面时,都将URL存储在“设置”中。 每次加载项加载时,使用document.getActiveViewAsync( https://dev.office.com/reference/add-ins/shared/document.getactiveviewasync )方法获取当前模式。 如果当前模式是幻灯片放映,请立即重定向到存储在设置中的URL。 我认为任何“状态”信息都必须存储。 You a ...
  • CustomTaskPanes集合是ThisAddIn类的属性。 因此,您可以使用“this”在ThisAddIn_Startup方法中访问它。 句法。 如果您没有在intellisense / autocomplete中看到该集合。 这个问题可能是由于某些可能性引起的: 您没有使用VSTO(Visual Studio Tools for Office)2005 SE。 您使用的是VSTO 2005 SE,但是您安装的是之前未完全删除的VSTO v3 CTP。 您正在为不支持自定义任务窗格的应用程序(所有O ...
  • 我在这里引用这些信息。 如果我理解你的想法,那看起来很有希望。 友好的iframe 这种技术适用于广告。 这不是一种真正的iframe加载技术,而是一种使用iframe来保存广告的方法。 神奇不在于iframe的加载方式,而在于主页,iframe和广告代码如何协同工作。 它的工作原理如下: 创建一个iframe。 将源设置为来自同一域的小型静态html页面 在iframe中,设置JavaScript变量inDapIF = true以告知广告它是在友好的iframe中加载的 在iframe中,创建一个以广告网 ...
  • 这不支持。 允许将JS嵌入到PPT中将会带来太多的安全隐患。 根据具体情况,您可以使用Web加载项来处理这种情况。 加载项可以与通用后端进行通信; 允许您在两种环境之间有效地传递信息。 This isn't supported. Allowing JS to be embedded within the PPT would simply present too many security concerns. Depending on the exact scenario, you might be able ...
  • Girish Raja提供了有关如何通过BCS集成CRM Online和SharePoint Point的精彩概述。 他的MSDN博客文章包含了他5月份TechEd视频演示的链接(视频中的第35分钟)以及源代码/说明的链接。 他的演示使用SharePoint内部部署,但提到一旦启用BCS,它将与SharePoint Online一起使用。 (它现在是)。 Girish Raja provides a great overview on how to integrate CRM Online and Shar ...
  • 它不是valid_elements and/or extended_valid_elements的问题,它的语法错误。 plugins: [ "code", "media" ] 它应该如下所示,插件用空格分隔 plugins:"code autolink", http://www.tinymce.com/wiki.php/Configuration:plugins 如果启用media插件,它不支持iframe 例如: http : //jsfiddle.net/ug247bsm/7/ I ...
  • 我对这个模块并不熟悉,但我看了他们的快速入门 from pptx.util import Inches from pptx import Presentation def open_PowerPoint_Presentation(oldFileName, newFileName, img, left, top): prs = Presentation(oldFileName) slide = prs.slides[3] pic = slide.shapes.add_picture( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。