-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Id erzeugen und in Tabelle schreiben (ohne Objekt)
PostPosted: Tue Nov 28, 2006 8:08 am 
Newbie

Joined: Wed Nov 01, 2006 11:19 am
Posts: 3
Location: Switzerland TG
Hibernate version: Nhibernate, weiss nicht genau

Mapping documents:

ActionType.hbm :

Code:
  <class
            name="Cyberline.WorkLogger.Model.ActionType, Cyberline.WorkLogger.Model"
            table="ActionTypes"
            optimistic-lock="version">

            <id name="Id" column="ActionTypeId">
              <generator class="guid" />
            </id>

            <property name="Name" type="StringClob"/>

            <property name="Description" type="StringClob" />

            <set name="Project" table="Bindings">
              <key column="ActionType"/>
              <many-to-many class="Cyberline.WorkLogger.Model.Project, Cyberline.WorkLogger.Model" column="Project"/>
            </set>

          </class>



Project.hbm :

Code:
  <class
            name="Cyberline.WorkLogger.Model.Project, Cyberline.WorkLogger.Model"
            table="Projects"
            optimistic-lock="version"
            >

            <id name="Id" column="ProjectId">
              <generator class="guid" />
            </id>

            <property name="Name" type="StringClob"/>

               <set name="ActionTypes" table="Bindings">
              <key column="Project"/>
              <many-to-many class="Cyberline.WorkLogger.Model.ActionType, Cyberline.WorkLogger.Model" column="ActionType"/>
            </set>

          </class>



Code between sessionFactory.openSession() and session.close():

Code:
ISession session = PersistenceLogic.Instance.GetNewSession();         
                    ITransaction transaction = session.BeginTransaction();
                    try
                    {
                        if (session.CreateCriteria(typeof(Project))
                        .Add(Expression.Eq("Name", proj.Name.Trim()))
                        .List()
                        .Count > 0)
                        {
                            throw new ArgumentException(String.Format("Cannot create the Project because there's already a Project with the same name '{0}'.", proj.Name.Trim()), "name");
                        }
                        else
                        {
                            ActionType act = new ActionType();
                            act.Description = "das ist mit einem ListSet ermöglicht";
                            act.Name = "ListSet";
                            proj.Id = Guid.NewGuid();
                            act.Id = Guid.NewGuid();

                            ListSet ls = new ListSet();
                            ls.Add(proj);

                            ListSet ls2 = new ListSet();
                            ls2.Add(act);

                            act.Project = ls;
                            proj.ActionTypes = ls2;

                            session.Save(proj);
                            session.Save(act);

                            transaction.Commit();
                        }
                    }
                    catch (Exception exp)
                    {
                        transaction.Rollback();
                        MessageBox.Show(exp.ToString());               
                    }
                    finally
                    {
                        session.Close();
                    }



Full stack trace of any exception that occurs:

NHibernate.ADOException: could not insert collection: [Cyberline.WorkLogger.Model.Project.ActionTypes#a47c5869-1e3498-342c-bdf989sdj90aa7] --->
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column "BindingId", table "WorkLogger.dbo.Bindings"; colum does not alow nulls.
INSERT fails.
The Statement has been terminated.

Name and version of the database you are using: SQL2005 Server, WorkLogger

The generated SQL (show_sql=true): ???

Debug level Hibernate log excerpt: ???

Mein Problem:

Ich habe folgendes Objektmodell

Image

und Datenbank Modell.

Image


Wie man sieht, habe ich zwei Objekte (ActionType und Project) die eine List auf das andere Object haben.
In der Datenbank habe ich dazu 3 Tabellen, AcionTypes und Projects sind über Bindings miteinander verbunden.
Darin wird einfach die ID von Project und von ActionType gespeichert, welche zusammengehören. Jedoch kann ich die BindingId nicht füllen.
Wie kann ich also in NHibernate eine neue GUID erzeugen und diese dann der Spalte BindingId hinzufügen?
Nochmals, ich habe kein Binding-Objekt, nur die Tabelle!

Wäre sehr froh wenn mir da jemand weiterhelfen könnte, denn nur mit der Hibernate Referenz bin ich nicht weiter gekommen :(

Vielen Dank im Voraus und Gruss

Whisky


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.