Tag: orm

Java Persistence API中的FetchType LAZY和EAGER的区别?

我是Java持久性API和Hibernate的新手。 Java Persistence API中的FetchType.LAZY和FetchType.EAGER什么区别?

entity framework代码来自同一个表的前两个外键

我刚刚开始使用EF代码,所以我完全是这个主题的初学者。 我想创build球队和比赛之间的关系:1比赛= 2队(主场,客队)和结果。 我认为创build这样的模型很容易,所以我开始编码: public class Team { [Key] public int TeamId { get; set;} public string Name { get; set; } public virtual ICollection<Match> Matches { get; set; } } public class Match { [Key] public int MatchId { get; set; } [ForeignKey("HomeTeam"), Column(Order = 0)] public int HomeTeamId { get; set; } [ForeignKey("GuestTeam"), […]

Doctrine2:在参考表中用多余的列来处理多对多的最佳方式

我想知道什么是最好的,最简单的方法来处理Doctrine2中的多对多关系。 假设我们已经有了Metallica 的木偶大师 ( Master of Puppets)等几张专辑。 但是请注意一个曲目可能会出现在更多的专辑中,比如Metallica的Battery – 三张专辑都以这个曲目为特色。 所以我需要的是专辑和曲目之间的多对多关系,使用第三个表格和一些额外的列(比如指定专辑中曲目的位置)。 其实我必须使用,正如Doctrine的文档所build议的那样,要实现这个function,必须使用双重一对多的关系。 /** @Entity() */ class Album { /** @Id @Column(type="integer") */ protected $id; /** @Column() */ protected $title; /** @OneToMany(targetEntity="AlbumTrackReference", mappedBy="album") */ protected $tracklist; public function __construct() { $this->tracklist = new \Doctrine\Common\Collections\ArrayCollection(); } public function getTitle() { return $this->title; } public function getTracklist() { […]

如何在NHibernate中加载关联而不重复?

我需要加载一个非常大的对象列表,有很多孩子和孩子的孩子。 最好的方法是什么? 我正在使用Oracle 11g数据库,并且已经编写了下面的方法,但是却导致了笛卡尔积(重复结果): public IList<ARNomination> GetByEventId(long eventId) { var session = this._sessionFactory.Session; var nominationQuery = session.Query<ARNomination>().Where(n => n.Event.Id == eventId); using (var trans = session.Transaction) { trans.Begin(); // this will load the Contacts in one statement nominationQuery .FetchMany(n => n.Contacts) .ToFuture(); // this will load the CustomAttributes in one statement nominationQuery .FetchMany(n => n.CustomAttributes) […]

Hibernate显示真正的SQL

如果我设置 <property name="show_sql">true</property> 在我的控制台的hibernate.cfg.xmlconfiguration文件中,我可以看到SQL。 但这不是真正的 SQL …我可以看到将直接传递到数据库的SQL代码吗? 例: 我懂了 select this_.code from true.employee this_ where this_.code=? 我可以看吗 select employee.code from employee where employee.code=12 真正的 SQL?

JPA JoinColumn vs mappedBy

有什么区别: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY) @JoinColumn(name = "companyIdRef", referencedColumnName = "companyId") private List<Branch> branches; … } 和 @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY, mappedBy = "companyIdRef") private List<Branch> branches; … }

jacksonJSON和Hibernate JPA问题的无限recursion

当试图将具有双向关联的JPA对象转换为JSON时,我不断收到 org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) 我发现的是这个线程 ,基本上推荐避免双向关联。 有没有人有一个解决方法这个春季bug的想法? ——编辑2010-07-24 16:26:22 ——- Codesnippets: 业务对象1: @Entity @Table(name = "ta_trainee", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})}) public class Trainee extends BusinessObject { @Id @GeneratedValue(strategy = GenerationType.TABLE) @Column(name = "id", nullable = false) private Integer id; @Column(name = "name", nullable = true) private String name; @Column(name = "surname", nullable = […]

NHibernate,Entity Framework,活动logging或linq2sql

我的团队正在ASP.NET MVC中开始一个新项目,我们想知道用什么技术来访问数据。 你如何决定哪一个是最好的? 哪个性能最好? 哪一个更容易使用和维护?

什么是N + 1 SELECT查询问题?

在对象关系映射(ORM)讨论中,SELECT N + 1通常被认为是一个问题,而且我明白,为了在对象世界中看起来很简单的事情做大量的数据库查询,有一些事情要做。 有没有人有更详细的解释这个问题?

如何映射复合键与休眠?

在这段代码中,如何为复合键生成一个Java类(如何在hibernate中复合键): create table Time ( levelStation int(15) not null, src varchar(100) not null, dst varchar(100) not null, distance int(15) not null, price int(15) not null, confPathID int(15) not null, constraint ConfPath_fk foreign key(confPathID) references ConfPath(confPathID), primary key (levelStation, confPathID) )ENGINE=InnoDB DEFAULT CHARSET=utf8;