FAQ Database Discussion Community


Hibernate One-To-Many Match multiple Ids

java,hibernate,one-to-many
I am using Hibernate 4 and JSF 2. Given the following mapping @Entity @Table(name = "feature") public class Feature { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column private String name; } @Entity @Table(name = "product") public class Product { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column private String...

Having trouble with mysql relationships?

mysql,many-to-many,relationship,one-to-many
I need two tables, one that shows a one to many relationship using three tables, and another table that shows a many to many relationship. I have managed to do the first 2 with were a query involving just one table, and a one to many involving 2 tables. One...

cakePHP 3.0 one to many relation

mysql,cakephp,many-to-many,one-to-many,cakephp-3.0
I have a projects table and an images' table. A project has many images, so it's a one to many relationship between the two tables. In the images view I can retrieve the project name that is related to an image by using: <?= $image->has('project') ? $this->Html->link($image->project->project_title, ['controller' => 'Projects',...

Django: set number of ForeignKey relations by integer value in another model

django,django-models,one-to-many
I am designing an Mturk application in Django where people rate Tweets for different outcomes (gender, personality, age, etc.). In my models I have three classes: Task (the Mturk task), Message (the Twitter message), and Outcome (the relationship I want the message annotated for). For each Task I want the...

Doctrine2 QueryBuilder: How to filter out entities having zero count for a OneToMany

symfony2,doctrine2,associations,one-to-many,query-builder
In my Dymfony2 / Doctrine2 application, I have a oneToMany relation between an object and its children. I want to select all objects which have no children. I'm stuck with various errors: SingleValuedAssociationField expected, Cannot add Having sth on non result variable, etc. $queryBuilder = $this ->createQueryBuilder('object') ->leftJoin('object.children', 'children') ->andWhere('children...

How do I create and insert one-to-many object with entity framework c#

c#,database,entity-framework,one-to-many
I'm trying to create an object and insert to the database but keep getting the same error no matter what I try. The row that I get the error on is ColumnGroupTest.ValidValues.Add(memberComment1); the error is error message NullReferenceException was unhandled by user code my models public class StoreColumnName { public...

Twig rendering of a mapped objects

symfony2,object,for-loop,twig,one-to-many
I am spinning my wheel to render an object in a twig template. I have 3 entities user >> customer >> account each one mapped to the next with a bi-directionnal one-to-many relationship. I want to fetch all accounts for a specific customer using this controller //... public function showAction($customerref)...

JPA Delete the “one” in a Many-to-One relation

jpa,delete,annotations,one-to-many,many-to-one
So i have these two classes: @Entity public class Tag { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parent") private List<TagValue> values; private String name; } @Entity public class TagValue { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String name; @ManyToOne...

Doctrine One to Many relationship

php,symfony2,doctrine2,doctrine,one-to-many
I got confuse in doctrine one to many relationship. Question 1: Correct me if I am wrong. I assume that when I try to $em = $this->getDoctrine()->getManager(); $product_repo = $em->getRepository('MyBundle:Product'); $products = $product_repo->findAll(); dump($products); I will see the related features attached to the $features variable, so when I use $products->getFeatures()...

Retrieving entities from a one to many relationship (Odata)

c#,.net,linq,odata,one-to-many
Summarizing, I have two main tables: Company and Employees, with a one-to-many relationship between them: employees belongs to a company. The Company entity has a property called Employees, which allows to get the employees who belongs to the specific Company. If I type in the browser this URL, it works...

Join by a single column instead of a composite primary key

hibernate,exception,jpa,one-to-many,joincolumn
I have single JPA entity and I would to add self join on this table. Table looks like e.g. @Entity @Table(name = "TABLE_A") @IdClass(TableAPk.class) public class TableA implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "COLUMN_1", nullable = false, length = 64) private String column_1;...

Linking tables in SQLAclhemy foreign_keys error [Flask]

json,flask,one-to-many,flask-sqlalchemy
I got two models Post and Category. class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) body = db.Column(db.Text) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) body_html = db.Column(db.Text) comments = db.relationship('Comment', backref='post', lazy='dynamic') category_id = db.Column(db.Integer, db.ForeignKey('categories.id')) category = db.relationship('Category',...

grails one to many with additional column

grails,relationship,one-to-many
In my Grails project I need to have a 1:N relationship between two domain classes. So, I've created the following domain class: class Receipt_HealthService { Receipt receipt HealthService healthService int quantity = 1 static constraints = { } } and in Receipt I have the following: @NotNull static hasMany =...

Entity Framework - Trouble with one-to-many relationship

c#,entity-framework,lazy-loading,virtual,one-to-many
We are making a code-first approach, and are having trouble with a one-to-many relationship. A Departement (Dep) has a list of Employees. Each Employee belongs to a Dep. (Required) I want to update the Employees name. (Without touching the Dep) I have reduced the sample to some simple classes: public...

How can i get the full related model in view in sails.js?

orm,sails.js,one-to-many,waterline,sails-mongo
I've created a sails.js application. I'm trying to get full related model Creator in view but I get only id... How can I do this? I'm doing this: Model Author.js module.exports = { attributes: { name: { type: 'string', required: true }, description: { type: 'string' }, history: { type:...

Getting objects from to-many relationship in Swift Core Data

ios,swift,core-data,one-to-many
I have been having some difficulties revolving around using to-many relationships in Core Data with Swift. My data model What I am trying to do is to use an instance of a Country and then display all of the Contacts that are citizens of that country. As I have been...

How efficient is Last_insert_id?

php,mysql,one-to-many,auto-increment,identifier
I recently came across a problem where I needed to be able to grab the last ID of a query I've inserted on a page. The process was quite simple, but I'd like some reassurance on how the process is done. Here's how my code is: $query30 = $db->query("INSERT `mybb_quickexample`...

Working with an One-to-many relationship in SQLAlchemy efficient way

python,sqlalchemy,one-to-many
I am a beginner SQL user. I have one DB with three tables, the table Person and the tables Hotel and Apartment. Each Person has just one relationship to one Hotel or Apartment but each Hotel or Apartment can have one or more persons assigned to them. Having the following...

Ruby on Rails - Help Adding Badges to Application

ruby-on-rails,ruby,rest,activerecord,one-to-many
I'm creating a rails application that is a backend for a mobile application. The backend is implemented with a RESTful web API. Currently I am trying to add gamification to the platform through the use of badges that can be earned by the user. Right now the badges are tied...

create dynamic default values for column in rails?

ruby-on-rails,postgresql,callback,migration,one-to-many
I am not sure how to go about this, or if there is a better way to do this, but I have a table called leads(many) and it references agent (one). I want to make a migration that sets a default value for the agent_id column in the leads table....

How to configure a One-to-Many relationship in EF

c#,entity-framework,one-to-many,model-binding,junction-table
I have the following model public class PageConfig : Base { // Properties Etc.. public ICollection<Image> ScrollerImages { get; set; } } My approach is to bind using a junction table { PageConfigID, ImageID }. In my model binder i tried the following.. modelBuilder.Entity<PageConfig>() .HasMany(x => x.ScrollerImages) .WithMany() .Map(x =>...

Django: “NOT NULL constraint failed” .user_id

python,django,one-to-many,one-to-one
So I created a model called SellPostImage so I can upload an image to the model which is the post called SellPost, and I have created two forms one called SellForm which would have the title, category etc. and another form that would handle the image uploading called SellPostImage. The...

Hibernate @OneToMany merge error

java,hibernate,postgresql,one-to-many
I'm the folloing having a trouble with my application: I've a @OneToMany relation as show above: The Bar class: @Entity public class Bar { @Id private Long id; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST) @JoinTable(name = "bar_foo_relation", joinColumns = { @JoinColumn(name = "id", referencedColumnName = "bar_id") }, inverseJoinColumns = {...

Ruby on Rails - Accessing Parent Attribute Though One to Many Association

ruby-on-rails,ruby,activerecord,associations,one-to-many
I'm fairly new to Ruby on Rails and am having issues using a one to many association I set up between two models. Here is the code for the two models that define the one to many association: class Location < ActiveRecord::Base has_many :reviews, -> { order 'created_at DESC' },...

OnetoOne and OneToMany in hibernate

hibernate,one-to-many,one-to-one
I have two entity classes User and WalletData I want to make a relation One user to many wallets with annotations but I do not know how. Also the relation I want to be pass by signature field located in the user entity. @Entity(name = "wallet_data") public class WalletData implements...

With a OneToMany relation between entities, how create the right queryBuilder with Doctrine (on the Inversed Side entity)

php,symfony2,doctrine2,one-to-many,query-builder
I have these 3 entities in my symfony2.6 project: Compteurs.php class Compteurs { /** * @var \PointsComptage * * @ORM\ManyToOne(targetEntity="PointsComptage", inversedBy="compteurs") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="pointscomptage_id", referencedColumnName="id") * }) */ private $pointsComptage; /** * @var \Doctrine\Common\Collections\Collection * * @ORM\OneToMany(targetEntity="ParametresMesure", mappedBy="compteurs") */ private $parametresMesure; ParametresMesure.php: class ParametresMesure { /** * @var Compteurs...

Reference to array of foreign keys

sql,associations,one-to-many,varray
Let's say I have a table T - its every row has a key (assume TID column). Now I have a second table A where for each row I'd like to have a list of values from TID. How could I achive this? I thought about creating VARRAY of values...

Core Data add object to-many relationship

ios,core-data,one-to-many
I am trying to implement Core Data to-many relationship with two entities - WardrobeList and Items. WardrobeList has a to-many relationship "items", so that one can add multiple items to a wardrobe. I have created NSManagedObject subclasses. Here are how they look. WardrobeList.h @class Item; @interface WardrobeList : NSManagedObject @property...

How to avoid persisting new object when oneToMany connection?

java,mysql,jpa,eclipselink,one-to-many
There is a three lines in returnreason-table and I don't want more lines there. User just choose one of the three reasons and I want only id to rma-table. Now it inserts a new line to reason-table every time when inserting new rma. I can take relation off between...

Cannot add or update a child row: a foreign key constraint fails

php,mysql,foreign-keys,one-to-many
So I've been wrestling with this for a couple of days now, googled and googled and moved things around to no avail :/. Here's the scenario: A Company can have many products. When I try to create a new company and a catalog for it, it creates the catalog but...

Entity Framework entity referencing another twice

entity-framework,one-to-many
I have this Product class for an order taking restaurant application: public class Product { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } public virtual ICollection<ServingChoice> ServingChoices { get; set; } } A product may...

How to fetch records from a class which has parent class reference?

ios,core-data,one-to-many,nsfetchrequest
I'm new to CoreData structure, I have two classes one is "Person.h" and another is "Education.h" which has one to many relations ship Person<--->> Education`. Here's the attributes for each classes, Person.h personID (unique) Number pName String pAge Number educations Set here, p stands for person Education.h educationID (unique) Number...

JPA Repository - one to many - issue with removing one child

java,jpa,repository,one-to-many
I have a one to many relationship between Father and Son. I am working with JPA Repository. If I delete a son with id 54 and then get all the sons again : sonRepository.delete(id); List<Son> sons = sonRepository.findAll(); I am getting this error : javax.persistence.EntityNotFoundException: Unable to find com.myapp.domain.Son with...

Mapping from many-to-many in database to one-to-many in domain

.net,many-to-many,entity-framework-6,one-to-many,ef-fluent-api
I have a mapping challange in Entity Framework. In the database I have a many-to-many relation between two tables with a intermediate table with the PK of the both as bellow: I need to map this relation to a one-to-many domain entities relation as bellow: How can I map this...

One-to-many relation based on multiple key (conditional) in Entity Framework

.net,sql-server,entity-framework,relational-database,one-to-many
So I have class User { ... public virtual ICollection<Book> AlreadyRead {get; set;} } class Book { ... public virtual User Owner {get; set;} public bool AlreadyRead {get; set;} } So what I need is that User.AlreadyRead return me Books by this User, where AlreadyRead == true I tryed this...

mysql query - one to many relations

mysql,database,one-to-many
I have this db: chef: id,name,surname cakes: idCake,idChef,cakeName I have to do a query that print the cakes name, grouped by chef name. How can I do with one single mysql query? My first idea is do 2 query: the first extract the chef names and id; for each chef...

Hibernate HQL query with condition on second table

oracle,hibernate,hql,condition,one-to-many
I have two tables (about football): Leagues and Teams which are in one-to-many relation. Now I want to get ALL Leagues but only with those teams which names start e.g. with "S". So far I have this: Query query = session.createQuery("select l from League l left join l.teams as t...

Convert One to Many to One to One Relationship MySQL

mysql,one-to-many,one-to-one
I have two MySQL tables we can call Foo and Bar. Both tables have a column called PrizeGroupId. the goal is to create a one-to-one relationship between these columns, and I have created stored procedures to add/edit Foo that update the corresponding row via the one-to-one relationship in Bar. The...

Core Data One-To-Many Relationship Memory Usage

ios,core-data,memory-management,one-to-many
I am using core data where I have object A which has a one-to-many relationship with object B. In practice there could be 1000s of Bs related to one A. My concern is that when I define the inverse of the one-to-many relationship, object A will have a NSSet containing...

How to map multiple One-to-Many association in Hibernate

java,hibernate,annotations,one-to-many
I have these 3 tables in my database CREATE TABLE IF NOT EXISTS `User`( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) CREATE TABLE IF NOT EXISTS `Project` ( `id` INT NOT NULL AUTO_INCREMENT, `manager` INT NOT NULL, `name` VARCHAR(255) NOT NULL DEFAULT...

Entity Framework (Code First) One to Many and One to One relations (with two entities). How to?

entity-framework,one-to-many,code-first,one-to-one,relationships
I'm trying to do this with EF Code First: There area two tables: Users and Areas. One User belongs to one required area and one Area can have zero or one User (as administrator). Then: Users *..1 Areas and Users 0..1 Areas The Users class: public class User { public...

One to Many entity framework error

entity-framework,mapping,one-to-many,code-first,asp.net-web-api2
I have 2 models, user & telephone. A user can have many telephone numbers. My User code: public class User { public User() { this.TelephoneNumbers = new List<Telephone>(); } public int UserId { get; set; } public string Forename { get; set; } public string Surname { get; set; }...

Implementing a class structure for one-to-many relationship. Swift

class,swift,structure,one-to-many
Basically I am trying to implement a class for a Person and Person's pets. In it's very simple form Person class and Pet class would be like this: class Person { var email : String! var name : String! var pets : [Pet]! init(userName: String) { email = userName //...

JPA and Hibernate persisting @manytoOne relationship

java,jpa,many-to-many,one-to-many,hibernate-cascade
I have this situation: @Entity @Table(name = "project_leader") public class ProjectLeader { @ManyToOne @JoinColumn(name = "projectId") @JsonBackReference(value = "project") private Project project; ... and related entity @Entity @Table(name = "project") public class Project { @OneToMany(fetch = FetchType.EAGER, mappedBy = "project", orphanRemoval = true) @Cascade(CascadeType.ALL) @JsonManagedReference(value = "project") private Set<ProjectLeader> projectLeaders...

Doctrine fetching indirectly associated objects

database,symfony2,doctrine,one-to-many,dql
I am trying to fetch associated objects through 3 tables (user, client, account). User has a one-to-many relationship to client, client has a one-to-many relationship to account. I easily fetch all the clients for one specific user using this simple code: $user = $this->getUser(); $id = $user->getId(); $user = $this->getDoctrine()->getRepository('AcmeUserBundle:User')->find($id);...

ED Code First One to Many Relationship Issue - ASP Identity

entity-framework,ef-code-first,one-to-many
I'm configuring a database for ASP Identity and I've hit a snag. I'm looking to create a One to Many relationship between two tables, which are ApplicationUser & OrganisationUnit. An OrganisationUnit can have multiple ApplicationUsers, with an ApplicationUser only belonging to one OrganisationUnit When I add a migration and update...

One To Many Relationship Using Vector Type

java,vector,relationship,one-to-many
I am new to Java programming. I just encountered the new concept of using vector type building a one-to-many relationship. Can you please give me an easy example of using vector type building a one-to-many relationship (including the class, implementation and an example using the class)? Really much appreciated....

Is it possible to combine many-to-many relationships with one-to-many relationships in a single query?

php,mysql,many-to-many,one-to-many
I have a MOVIE table that includes a many to many relationship with a genre as well as a review table that has a one to many relationship. AKA, a movie can have many genres and a genre can have many movies. A movie can have many reviews. My problem...

ID not saved in OneToMany relationship

symfony2,doctrine,one-to-many
I'm working on a project using Symfony2. But I'm running into a problem. I have an entity Purchase and another, TypePurchase. They have an OneToMany-relationship, but when I look inside of the table of TypePurchase, the Purchase entity ID is not saved. It's value is null. I already tried $types->setPurchase($this)...