composite-key

Hibernate returns invalid results with composite key.

I'm getting the strangest results. I have a class with a composite key. If i do the following query: from LOVEJB l order by l.canonicalId desc my results are not ordered by the 'canonicalId' column I asked for. Instead, the canonical id result is like: 823 823 822 823 ,,, Can someone give me some pointers on how should I tr...

JPA Composite Key + Sequence

Hi, Is it possible in plain JPA or JPA+Hibernate extensions to declare a composite key, where an element of the composite key is a sequence? This is my composite class: @Embeddable public class IntegrationEJBPk implements Serializable { //... @ManyToOne(cascade = {}, fetch = FetchType.EAGER) @JoinColumn(name = "APPLICAT...

MySQL Question - Unique Key Not functioning correctly, or am I misunderstanding?

I'm trying to create a relation where any of four different parts may be included, but any collection of the same parts should be handled as unique. Example: An assignment must have an assigned company, may optionally have an assigned location, workgroup and program. An assignment may not have a workgroup without a location. Let's assu...

Unexpected proxy objects in Nhibernate with composite ID's

I have a data structure which uses composite ids (Which I dont wish to change to single) Everything loads fine except for many-to-one joins which if the join is empty, instead of mapping the property to null, maps it to an empty proxy object. I have written an ugly work around( see bleow). Any solutions to this? private Node _Parent; ...

SQL composite key query

to reference this again http://stackoverflow.com/questions/501347/sql-products-productsales how could i do something like that when the primary key is made up of two columns and not one? so products has two columns as PK, and productsales has two columns as FK. here is the solution with a 1-column key: SELECT p.[name] FROM products p...

nhibernate Composite Foregin key

People, I have a horrible legacy DB that i have to map in nHibernate, that im not allowed to change. There is a horrible tree structure called FaultCodes with these fields: ID int eventID int treeID int (unique per eventID) parentTreeID int ID is the PK, its used by other tables to join to this one. Problem is, the parent/child r...

In a join table, what's the best workaround for Rails' absence of a composite key?

create_table :categories_posts, :id => false do |t| t.column :category_id, :integer, :null => false t.column :post_id, :integer, :null => false end I have a join table (as above) with columns that refer to a corresponding categories table and a posts table. I wanted to enforce a unique constraint on the composite key category_id, p...

ManyToMany in Hibernate without composite keys

I am dealing with legacy database. And I am writing unit test using pojos & hibernate & HSQLDB. And I am getting the following error: 17:09:03,946 ERROR SchemaExport:349 - Attempt to define a second primary key in statement Let's say I have Post and Tag entities (and of course their tables posts and tags). And there is another table to...

nHibernate - stored procedures and composite keys

I'm trying to map the output of a stored procedure to an object in my project using nHibernate. The object is delcared like this: public class NewContentSearchResult { public string Name { get; set; } public string ContentType { get; set; } public int Count { get; set; } public int CMIId { get; set; } public int Fea...

Saving a grails object with a composite id

The answer to this may be obvious but how do you save an object, in grails, that has a composite id. I have an object that has a composite id including a long and a date and I am trying to save an instance of the object from the update method of another classes controller, and using (object).save() isn't working. Any tips or suggestion...

JPA createQuery with a partial composite key

The code schematic below works fine but it breaks our coding guidelines due to the unchecked cast. How can this be re-written to use createQuery or otherwise avoid the unchecked cast? Note 1: using hibernate Note 2: @SuppressWarnings("unchecked") is not the answer @Entity @Table(name="Foo") class Foo { @EmbeddedId FooPK pk; ... ...

Should I use a composite key for a map table, which is also used for a foreign key?

I am using ASP.NET and the Entity Framework to make a website. I currently have a map table for a many to many relationship between... let's say users and soccer teams. So: Users Teams UserTeams Part 1: Is it best practice to use a composite key for the primary key of the map table? In other words: UserTeams table PK UserId PK Te...

Database Design: Composite key vs one column primary key

A web application I am working on has encountered an unexpected 'bug' - The database of the app has two tables (among many others) called 'States' and 'Cities'. 'States' table fields: ------------------------------------------- idStates | State | Lat | Long ------------------------------------------- 'idStates' is an auto...

Postgres: How to do Composite keys?

I cannot understand the syntax error in creating a composite key. It may be a logic error, because I have tested many varieties. How do you create composite keys in Postgres? CREATE TABLE tags ( (question_id, tag_id) NOT NULL, question_id INTEGER NOT NULL, tag_id SERIAL NOT NULL, ...

nHibernate Composite Key Class Type Mismatch

I have a legacy table with composite keys that are mapped to 3 other tables, since this table have other attributes in it, since it is not a simple mapping table, I can't use the many-to-many set solution to map this. The following is what I have done: <class name="classA" table="A"> <composite-id name="ID" class="AKey"> <key-many-to...

Composite Key on a Self Referencing Table

We have a composite primary key for the site table defined below. Functionally, this does exactly as we would like it to. Each site should have a parent site of the same district. Defining the table in this way allows specifically for that. CREATE TABLE [dbo].[site]( [site_number] [nvarchar](50) NOT NULL, [district_id] [bigint] ...

Composite Primary Key performance drawback in MySQL

We have a table with a composite Primary key consisting of three fields (and it is in MySQL 5.1). There are near 200 inserts and 200 selects per second on this table, and the size of the table is around 1 million rows and it is increasing. My question is, does the "Composite Primary Key" decrease the performance of the Inserts and Select...

Is it possible to map a composite key in fluent nhibernate where half of the key is an identity field in the database?

As the question states, is it possible to map a composite key in fluent nhibernate (or non fluent i suppose) where one of the two fields used in the composite is an identity field? I have a table where one part of the primary key is an identity field and the other is a tenant id. This is a legacy database where the composite key is used...

Is there a Linq operation to determine whether there are items in a collection who have the same values for a pair of properties?

C#: I have a collection of objects . T has 2 properties. Property A and Property B. The rule that this collection needs to adhere to is that the combination of values for A and B must be unique within the collection. In other words, A and B need to serve as a composite primary key. Is there an operation in Linq I can use to check this c...

Surrogate key as a foreign key over composite keys

I realise there might be similar questions but I couldn't find one that was close enough for guidance. Given this spec, Site --------------------------- SiteID int identity Name varchar(50) Series --------------------- SiteID int SeriesCode varchar(6) ... --SeriesCode will be unique for every unique SiteID Episod...