简体   繁体   English

什么是单向多对多关联?

[英]What is unidirectional many-to-many association?

As far as I understand, Many to Many association between 2 entities A and B mean that A can have more than one values in B and B can have more than one values in A . 据我了解, Many to Many 2个实体AB之间的关联意味着一个可以在BB不止一个值可以在一个以上的值。

If that is correct what does unidirectional many to many association mean ? 如果那是正确的,那么unidirectional many to many association意味着什么? How is it different from bidirectional many to many mapping ? bidirectional many to many mapping有何不同?

As the name suggests many to many means bidirectional ! 顾名思义many to many双向意味着many to many

I think you are getting confused with database tables and its corresponding entities. 我认为您对数据库表及其对应的实体感到困惑。

From DB perspective: Many to many would be implemented using third table, which holds entries from both the tables. 从数据库角度来看:使用第三个表可以实现很多对很多表,该表包含两个表中的条目。

From java entities perspective: its upto you, if you want it to be bidirectional or unidirectional. 从Java实体的角度来看:如果您希望它是双向的或单向的,则由您决定。 What it simple means, is that, you can have a collection of Students in Module, but you may not want to care, to how many Modules student belongs to. 它的简单含义是,您可以在模块中拥有一组学生,但是您可能并不希望知道该学生属于多少个模块。

class Student{
//attributes and methods
}

class Module{

Collection<Student>  students;

//other attributes and methods.

}

Now, being in administration of some institution, I want to have flexibility of creating modules and assigning students to this module. 现在,在某个机构的行政管理下,我想灵活地创建模块并将学生分配给该模块。 I would prefer many-many unidirectional. 我希望有很多单向的。 So, here actually if you see, there are many modules as well as many students( i hope you can make out what i mean). 因此,实际上,如果您看到的话,这里有很多模块以及很多学生(我希望您能明白我的意思)。 Having said that, you are not restricted to find out if a Student belongs to Java module or not. 话虽如此,您并没有被限制去查明学生是否属于Java模块。 I hope it makes it little more clear. 我希望它能使它变得更加清晰。

Unidirectional means that, for example, A has a reference to B s, but not the other way around. 单向意味着,例如, A引用了B s,但没有相反的引用。

many to many means bidirectional No . 多对多表示双向 No。 The many to many concept is for database table mapping. many to many概念是用于数据库表映射的。 Hibernate uses it (and other x-to-x ) to generate the proper database table schema. Hibernate使用它(和其他x-to-x )来生成正确的数据库表模式。 The x-directional concept is for java objects. x-directional概念适用于Java对象。

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

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