Search Results

Search found 2412 results on 97 pages for 'relationship'.

Page 19/97 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • EntityManager does not update on flush()

    - by Sara
    Java EJB's EntityManager does not update data from a Consumer. A Consumer logs into a shop, buys some stuff and wants to look at his shopping-history. Everything is displayed but his last purchase. If he logs out and in, it shows. I have used JPA to persist buys/purchases (that are mapped to the Consumer)to DB. It seems like purchases from this session can't be detected. Code: public Buys buyItem(Consumer c, int amount) { Buys b = new Buys(); b.setConsumerId(c); b.setContent("DVD"); b.setPrice(amount); em.persist(b); em.flush(); return b; } public Collection getAllBuysFromUser(Consumer consumer) { Collection collection = consumer.getBuysCollection(); return collection; } Help!? Flush does not do the trick...

    Read the article

  • Hibernate not saving foreign key, but with junit it's ok

    - by Leonardo
    Hi All, I have this strange problem. In a J2ee webapp with spring, smartgwt and hibernate, it happens that I have a class A wich has a set of class B, both of them mapped to table A and table B. I wrote a simple test case for testing the service manager which is supposed to do insert, update, delete and everything work as expected especially during insert. In the end I have one record in A and records in B with foreign key to A. But when I try to call the service from the web app, the entity in B are saved without a foreign key reference. I am sure that the service is the same. One thing I noticed is that enabling hibernate logging, seems that when the service is called from the application, one more update is made: insert A insert B update A update B update B (foreign key only) update A <--- ??? update B <--- ??? Instead, when junit test case is run, the update is as follows: insert A insert B update A update B update B (foreign key only) I suppose the latest update is what is causing the erroe, maybe it is overwriting values. Considering that the app is using spring, with the well known mechanism of DAO + Manager, where can I investigate to solve this issue ? Someone told me that the session is not closed, so hibernate would do one more update before release the objects by itself. I am pretty sure that all the configuration hbm, xml, and the rest are fine...but I maybe wrong. thanks

    Read the article

  • Help needed with Linq To Sql Query

    - by fearofawhackplanet
    I have the concept of valid/ordered transitions. So for example, it's not possible to move to status In progress from status Complete. Current and Next in table StatusTransition are FK (StatusType.Id). The Linq generator has created the following relations: Child Property Name: StatusTransitions1 Parent Property Name: StatusType1 Participating Properties: StatusType.Id -> StatusTransition.Next Child Property Name: StatusTransitions Parent Property Name: StatusType Participating Properties: StatusType.Id -> StatusTransition.Current I'm normally ok with Linq but I'm having difficulty getting the list of valid Next StatusTypes from the Current status. public List<StatusType> GetValidStatusTransitions(int statusId) { // trying to write something like the following // (obviously not correct) return _statusRepository .Where(s => s.Id == statusId) .Next.StatusTypes; }

    Read the article

  • Circular database relationships. Good, Bad, Exceptions?

    - by jim
    I have been putting off developing this part of my app for sometime purely because I want to do this in a circular way but get the feeling its a bad idea from what I remember my lecturers telling me back in school. I have a design for an order system, ignoring the everything that doesn't pertain to this example I'm left with: CreditCard Customer Order I want it so that, Customers can have credit cards (0-n) Customers have orders (1-n) Orders have one customer(1-1) Orders have one credit card(1-1) Credit cards can have one customer(1-1) (unique ids so we can ignore uniqueness of cc number, husband/wife may share cc instances ect) Basically the last part is where the issue shows up, sometimes credit cards are declined and they wish to use a different one, this needs to update which their 'current' card is but this can only change the current card used for that order, not the other orders the customer may have on disk. Effectively this creates a circular design between the three tables. Possible solutions: Either Create the circular design, give references: cc ref to order, customer ref to cc customer ref to order or customer ref to cc customer ref to order create new table that references all three table ids and put unique on the order so that only one cc may be current to that order at any time Essentially both model the same design but translate differently, I am liking the latter option best at this point in time because it seems less circular and more central. (If that even makes sense) My questions are, What if any are the pros and cons of each? What is the pitfalls of circular relationships/dependancies? Is this a valid exception to the rule? Is there any reason I should pick the former over the latter? Thanks and let me know if there is anything you need clarified/explained. --Update/Edit-- I have noticed an error in the requirements I stated. Basically dropped the ball when trying to simplify things for SO. There is another table there for Payments which adds another layer. The catch, Orders can have multiple payments, with the possibility of using different credit cards. (if you really want to know even other forms of payment). Stating this here because I think the underlying issue is still the same and this only really adds another layer of complexity.

    Read the article

  • Creating a Group of Groups in Django

    - by Greg
    I'm creating my own Group model; I'm not referring to the builtin Group model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group. The admin interface won't let me create a group without entering a parent. I get the error personnel_group.parent_id may not be NULL. My Group model looks like this: class Group(models.Model): name = models.CharField(max_length=50) parent = models.ForeignKey('self', blank=True, null=True) order = models.IntegerField() icon = models.ImageField(upload_to='groups', blank=True, null=True) description = models.TextField(blank=True, null=True) How can I accomplish this? Thanks.

    Read the article

  • Multiple has_many's of the same model

    - by Koning Baard
    I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many :messages_to_person, :foreign_key => :to_user_id, :class_name => :messages Message belongs_to :to_person, :foreign_key => :to_user_id, :class_name => :person belongs_to :from_person, :foreign_key => :to_user_id, :class_name => :person And this view: person#show <% @person.messages_to_person.each do |message| %> <%=h message.title %> <% end %> But I get this error: TypeError in People#show Showing app/views/people/show.html.erb where line #26 raised: can't convert Symbol into String Extracted source (around line #26): 23: <%=h @person.biography %> 24: </p> 25: 26: <% @person.messages_to_person.each do |message| %> 27: 28: <% end %> 29: I basicly want that people can send eachother messages. Can anyone help me? Thanks.

    Read the article

  • Non-normalized association with legacy tables in Rails and ActiveRecord

    - by Thomas Holmström
    I am building a Rails application accessing a legacy system. The data model contains Customers which can have one or more Subscriptions. A Subscription always belong to one and only one Customer. Though not needed, this association is represented through a join table "subscribes", which do not have an id column: Column | Type | Modifiers -----------------+---------+----------- customer_id | integer | not null subscription_id | integer | not null I have this coded as a has_and_belongs_to_many declarations in both Customer and Subscription class Customer < Activerecord::Base has_and_belongs_to_many :subscriptions, :join_table => "subscribes", :foreign_key => "customer_id", :association_foreign_key => "subscription_id" end class Subscription < Activerecord::Base has_and_belongs_to_many :customers, :join_table => "subscribes", :foreign_key => "subscription_id", :association_foreign_key => "customer_id" end The problem I have is that there can only ever be one customer for each subscription, not many, and the join table will always contain at most one row with a certain customer_id. And thus, I don't want the association "customers" on a Subscription which returns an array of (at most one) Customer, I really do want the relation "customer" which returns the Customer associated. Is there any way to force ActiveRecord to make this a 1-to-N relation even though the join table itself seems to make it an N-to-M relation? --Thomas

    Read the article

  • Java sockets: multiple client threads on same port on same machine?

    - by espcorrupt
    I am new to Socket programming in Java and was trying to understand if the below code is not a wrong thing to do. My question is: Can I have multiple clients on each thread trying to connect to a server instance in the same program and expect the server to read and write data with isolation between clients" public class Client extends Thread { ... void run() { Socket socket = new Socket("localhost", 1234); doIO(socket); } } public class Server extends Thread { ... void run() { // serverSocket on "localhost", 1234 Socket clientSock = serverSocket.accept(); executor.execute(new ClientWorker(clientSock)); } } Now can I have multiple Client instances on different threads trying to connect on the same port of the current machine? For example, Server s = new Server("localhost", 1234); s.start(); Client[] c = new Client[10]; for (int i = 0; i < c.length; ++i) { c.start(); }

    Read the article

  • MySQL - Find entries that refer to a specified index.

    - by Conor H
    Hi, So I have a booking system where I have a 'lesson_type' table with 'lesson_type_id' as PK. I have a constraint in place here so I can't delete a lesson_type if there are bookings made for that lesson_type. I would like to be able to determine if this lesson_type_id is being referred to by any entries in the bookings table (or any other table for that matter) so I can notify the user gracefully. i.e. not have a mysql error be thrown when they try and delete a record. What kind of query would I use for this? Thanks.

    Read the article

  • Problem in mutiple :dependent=> :destroy when multiple polymorphic is true

    - by piemesons
    I have four models question, answer, comment and vote.Consider it same as stackoverflow. Question has_many comments Answers has_many comments Questions has_many votes answers has_many votes comments has_many votes Here are the models (only relevant things) class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true has_many :votes, :as => :votable, :dependent => :destroy end class Question < ActiveRecord::Base has_many :comments, :as => :commentable, :dependent => :destroy has_many :answers, :dependent => :destroy has_many :votes, :as => :votable, :dependent => :destroy end class Vote < ActiveRecord::Base belongs_to :votable, :polymorphic => true end class Answer < ActiveRecord::Base belongs_to :question, :counter_cache => true has_many :comments, :as => :commentable , :dependent => :destroy end Now the problem is whenever i am trying to delete any question/answer/comment its giving me an error NoMethodError in QuestionsController#destroy undefined method `each' for 0:Fixnum if i remove this line from any of the model (question/answer/comment) has_many :votes, :as => :votable, :dependent => :destroy then it works perfectly. It seems there is a problem while deleting the records active record is not able to find out the proper path because of multiple joins within the tables.

    Read the article

  • Open Source - EER Modeling Tool

    - by Nick Fergis
    Is there a good open source or reasonably priced EER modeling tool for MySQL besides MySQL Workbench? I find the MySQL Workbench interface to be clunky. I would like to be able to manage my production schema beginning all design changes in the EER and propogating those out to my schema for created and altered tables. Is anyone use a tool they love to manage their environments in this way? Thanks. - Nick

    Read the article

  • IPhone CoreData: How should I relate many child entities to thier parents

    - by Robert
    I am trying to import data from a database that uses primary key / forign key relations to a core data database in Xcode. I have code that creates hundreds of child entities in a managed object context: Each child has an ID that corresponds to a parent. child1 parentID = 3 child2 parentID = 17 child3 parentID = 17 ... childn parentID = 5 I now need to relate each child to its parent. The parents are all stored in persistent memory. My first thought was to preform a fetch for each child to get its parent. However, I think this would be slow. Am I correct? How should I do this instead?

    Read the article

  • Validate dependent model validation and show error message.

    - by piemesons
    Just taking a simple example. We have a question on stackoverflow and while posting a question we want to validate title_of_question, description_of_question that they should be present. Now we have a another model tag having habtm relationshio with question model. How to validate that while saving the question. Means question must have some tags. here the code:-- Models:-- class Question < ActiveRecord::Base belongs_to :user has_and_belongs_to_many :tags has_many :comments, :as => :commentable has_many :answers, :dependent => :destroy validates_presence_of :title, :content, :user_id end class Tag < ActiveRecord::Base has_and_belongs_to_many :questions validates_presence_of :tag end Form for entering question and tag <div class="form"> <% form_for :question ,@question, :url => {:action => "create" } do |f| %> <fieldset> <%= f.error_messages %> <legend>Post a question</legend> <div> <%= f.label :title %>: <%= f.text_field :title, :size => 100 %> </div> <div> <%= f.label :content ,'Question' %>: <%= f.text_area :content, :rows => 10, :cols => 100 %> </div> <div> <%= label_tag 'tags' %>: <%= text_field_tag 'tag' ,'',:size=> 60 %> add multiple tag using comma </div> <div> <%= submit_tag "Post question" %> </div> </fieldset> <% end %> </div> From Controller.. (Right now question will be saved without validating tag) def create @question = Question.new(params[:question]) @question.user_id=session[:user_id] if @question.save flash[:notice] = "Question has been posted." redirect_to question_index_path else render :action => "new" end end questions_tags table has been created. One approach is creating a virtual column using attribute accessors. another approach is validate associated. right now assuming new tags can be created.(but not duplicate).

    Read the article

  • cache_counter for habtm

    - by piemesons
    Hello How can use cache_counter in a habtm. For example a question has many tags and a tag can belong to many questions. question habtm tags Now i want to find out number of questions belonging to every tag. One way is counting everytime. But, in case of one_to_many i done same thing in this way. Like one question has many answers. then in answer model i specified belongs_to :question,:cache_counter=>true It solved my problem. So how to do the same in habtm.

    Read the article

  • How to add a new entry to a multiple has_many association?

    - by siulamvictor
    I am not sure am I doing these correct. I have 3 models, Account, User, and Event. Account contains a group of Users. Each User have its own username and password for login, but they can access the same Account data under the same Account. Events is create by a User, which other Users in the same Account can also read or edit it. I created the following migrations and models. User migration class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.integer :account_id t.string :username t.string :password t.timestamps end end def self.down drop_table :users end end Account migration class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.string :name t.timestamps end end def self.down drop_table :accounts end end Event migration class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.integer :account_id t.integer :user_id t.string :name t.string :location t.timestamps end end def self.down drop_table :events end end Account model class Account < ActiveRecord::Base has_many :users has_many :events end User model class User < ActiveRecord::Base belongs_to :account end Event model class Event < ActiveRecord::Base belongs_to :account belongs_to :user end so.... Is this setting correct? Every time when a user create a new account, the system will ask for the user information, e.g. username and password. How can I add them into correct tables? How can I add a new event? I am sorry for such a long question. I am not very understand the rails way in handling such data structure. Thank you guys for answering me. :)

    Read the article

  • SQL database self interaction entity

    - by Ricardo Costa
    I've been working on a database, wich is referent to an Aeroport management. I'm having a problem that it's freaking me out.. What i'm trying to do is, assuming that a client wants to know the distance between 2 locations, in miles or kms. As an example, if the user wants to know the distance between London and Amsterdam, should that distance be calculated by a formule or should it be already stored on the database? (1,N) ____________ ____________|__ | | | | | City/Airport |<---------| |______________| How can i show to user the distance between his 2 choices? RicardoCosta

    Read the article

  • Example of user-defined integrity rule in database systems?

    - by Pavel
    Hey everyone. I'm currently preparing for my exams and would like to know some examples of user-defined integrity rule in database systems. As far as I understand, it means that I can set up certain conditions for the columns and when data is inserted it needs to fulfill these conditions. For example: if I set up a rule that an ID needs to consist of 5 integers ONLY then when I insert a row with ID which is made up of integers and some chars then it won't accept it and return an error. Could someone confirm and give me some opinion on that? Thank you very much in advance!

    Read the article

  • What's does "cardinality of an relationship" mean in Core Data?

    - by dontWatchMyProfile
    From the docs: If all of a managed object's relationship delete rules are Nullify, then for that object at least there is no additional work to do (you may have to consider other objects that were at the destination of the relationship—if the inverse relationship was either mandatory or had a lower limit on cardinality, then the destination object or objects might be in an invalid state). Does someone have an example of this cardinality thing? What's this good for and what's important to know about this? (sounds very important...)

    Read the article

  • Multiple column foreign key contraints

    - by eugene4968
    I want to setup table constraints for the following scenario and I’m not sure how to do it or if it’s even possible in SQL Server 2005. I have three tables A,B,C. C is a child of B. B will have a optional foreign key(may be null) referencing A. For performance reasons I also want table C to have the same foreign key reference to table A. The constraint on table C should be that C must reference its parent (B) and also have the same foreign key reference to A as its parent. Anyone have any thoughts on how to do this?

    Read the article

  • [Ruby on Rails] how to add a new entry with a multiple has_many association?

    - by siulamvictor
    I am not sure am I doing these correct. I have 3 models, Account, User, and Event. Account contains a group of Users. Each User have its own username and password for login, but they can access the same Account data under the same Account. Events is create by a User, which other Users in the same Account can also read or edit it. I created the following migrations and models. User migration class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.integer :account_id t.string :username t.string :password t.timestamps end end def self.down drop_table :users end end Account migration class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.string :name t.timestamps end end def self.down drop_table :accounts end end Event migration class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.integer :account_id t.integer :user_id t.string :name t.string :location t.timestamps end end def self.down drop_table :events end end Account model class Account < ActiveRecord::Base has_many :users has_many :events end User model class User < ActiveRecord::Base belongs_to :account end Event model class Event < ActiveRecord::Base belongs_to :account belongs_to :user end so.... Is this setting correct? Every time when a user create a new account, the system will ask for the user information, e.g. username and password. How can I add them into correct tables? How can I add a new event? I am sorry for such a long question. I am not very understand the rails way in handling such data structure. Thank you guys for answering me. :)

    Read the article

  • How do I show all group headers in Access 2007 reports?

    - by Newbie
    This is a question about Reports in Access 2007. I'm unsure whether the solution will involve any programming, but hopefully someone will be able to help me. I have a report which lists all records from a particular table (call it A), and groups them by their associated record in a related table (call it B). I use the 'group headers' to add the information from table-B into the report. The problem occurs when I filter the records from table-A that are shown in the report. If I filter out all table-A records that relate to a particular record (call it X) in table-B, the report no longer shows the record-X group header. As a possible workaround, I have tried to ensure that I have one empty record in table-A for each of the records in table-B. That way I can specify NOT to filter out these empty records. However, the outcome is ugly one-record-high blank spaces at the start of each group in the report. Does anyone know of an alternative solution?

    Read the article

  • Importing data and keeping ids and relationships

    - by Justin Hamade
    I am working on cleaning up a mess that another programmer started. The created 2 identical databases for different locations but that obviously caused major issues. They are using cakePHP and there are quite a few relationships. I am pretty sure I will have to write a script to import that data from on DB to the other and keep all the relationships but was wondering if there is an easier way to do it.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >