one-to-many

Hibernate - One to many relationship and orphanRemoval cascade

北城以北 提交于 2019-12-03 13:28:57
I have a basic one to many relation parent / child like in the chapter 21 of Hibernate references book. The cascade is only from child to parent (persist cascade only because I don't want to delete the parent if I delete a child). When I add a child to the parent and I save the child, I have a TransientObjectException... @Entity public class Parent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(mappedBy = "parent", orphanRemoval = true) private List<Child> childs; public List<Child> getChilds() { return childs; } public void setChilds

Filter SQLAlchemy query result object's one-to-many attribute

荒凉一梦 提交于 2019-12-03 12:46:41
Say I have a couple objects, having a one-to-many relationship, something like class Parent(): //id, other cols, etc children = relationship("Child", backref="parent") class Child(): parent_id = Column(Integer, ForeignKey("parent.id") child_type = Column(Enum("a","b")) Now, I want to query Parent objects, but have their children filtered by child_type, ie something like session.query(Parent).join(Parent.children).filter(Child.child_type == "a") This just returns the Parent with all the children, basically disregarding the filter. Is this result at all possible or do I have to also query Child?

How to map an ArrayList of primitives to a single column?

时间秒杀一切 提交于 2019-12-03 12:42:02
Let's say I have the following situation: Object Car has an ArrayList of prices, which are all numbers. Is it possible in Hibernate to save all the prices in a single column? I know this violates the first normal form but there might be cases when you don't want them to be saved in a separate table like it's classically done in One-To-Many or Many-To-Many relationships. In JDO I'd do this easily by saving the ArrayList in a BLOB column. Some useful related SOF questions: ArrayList of primitive types in Hibernate and Map ArrayList with Hibernate . Any idea will be highly appreciated! Chris

How to remove Create and Edit… from many2one field.?

泄露秘密 提交于 2019-12-03 12:27:28
问题 Please advice me How to remove "Create and Edit..." from many2one field.? that item shows below in the many2one fields which I filtered with domain option. OpenERP version 7 回答1: I don't have much idea. Maybe for that you have to make changes in web addons. But an alternative solution is that you can make that many2one field selection . Add widget="selection" attribute in your xml. <field name="Your_many2one_field" widget="selection"> 回答2: Many2one widget (default) Options : Other possible

Doctrine OneToMany relationship error

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:32:00
I am trying to set up some ManyToOne/OneToMany relationships on objects in my database using Doctrine (2.2.3+) via Symfony2 (2.3.0) and am getting a strange error. Here are the relevant parts of the objects (many attributes to one product): /** * Product * * @ORM\Table(name="product") * @ORM\Entity */ class Product { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; ... /** * * @OneToMany(targetEntity="ProductAttributes", mappedBy="product") */ protected $product_attributes; public function __construct() { $this-

JSON to Core Data with Relationships

孤街浪徒 提交于 2019-12-03 10:14:55
问题 Following Ray Wenderlich's new tutorial I was able to get JSON data and store it into Core data. I am having a really hard time understanding how to do this with relationships in Core Data though. Here is my Data Model: Here is my JSON: { "results": [ { "name": "Trivia 1", "objectId": "1000", "createdAt": "2012-08-31 18:02:52.249 +0000", "updatedAt": "2012-08-31 18:02:52.249 +0000", "questions": [ { "text": "Question 1" }, { "text": "Question 2" }, { "text": "Question 3" } ] } ] } And finally

Database design for comments and replies

喜你入骨 提交于 2019-12-03 09:38:25
问题 I want to create two tables one with comments and another with replies, with a one to many relationship between them. But what if they can also reply to replies, how should it be changed then? This is what I have for the one to many, but I don't know how it should look if there can also be replies for a reply. Comments: • Id • Title • Text Replies: • Id • Title • Text • Comment id Thanks in advance. 回答1: You could just use one table, which includes a ParentID field. If the record has no value

OpenERP : create new record ,one2many many2one relationship

ⅰ亾dé卋堺 提交于 2019-12-03 09:16:07
I have created on2many field in class A and other field nombre (integer): 'Inventaire' : fields.one2many('class.b','id_classb'), 'nombre' : fields.integer('Nombre'), In class b : 'id_classb' : fields.many2one('class.a', 'ID_classA'), 'ql' : fields.integer('QL'), I want to create a function in class a that create records for object b according to the value of nombre field. for example if nombre =3 I should create 3 object of class b here is my function: def save_b(self, cr, uid, ids, field_name, arg, context): a= self.browse(cr, uid, id) nbr=a.nombre num=22 for i in range(nbr): num+=1 self

Hibernate: OneToMany save children by cascade

走远了吗. 提交于 2019-12-03 08:40:42
问题 In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try A @Entity public class Parent { // id and other attributes @OneToMany(mappedBy = "parent") @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.ALL) protected List<child> children; Parent.class try B @Entity public class Parent { //

Symfony 2 Embedded forms using one to many db relationship

狂风中的少年 提交于 2019-12-03 07:27:35
I'm have a problem embedding forms from different entities in one form, my form is being displayed with firstname [input] lastname [input] address - but the address has no input next to it. Basically I want to create a form where the user can add first name, last name, address1, address2, city, country ect and submit it it as one, although it's different tables. The main form is no problem the only issue I'm having is with the second embedded form. Any help would be greatly appreciated. Here is my code: Member class: namespace Pomc\MembersBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *