-->
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: mapping component collections with attributes
PostPosted: Thu Dec 11, 2008 6:34 pm 
Newbie

Joined: Tue Sep 18, 2007 10:35 am
Posts: 8
I'm running into a problem when I try to map component collections via attributes. It doesn't seem that the additional properties of the component get persisted. When I create the database with the SchemaTool the columns don't get created. Here are my two classes. What am I doing wrong?

Code:
[Class(Lazy = false)]
public class NewsItem : Entity
{
    [Property(NotNull = true)]
    public string Title { get; set; }

    [Property(NotNull = true, Length = 8000)]
    public string Body { get; set; }

    private IList<NewsImage> images = new List<NewsImage>();

    private DateTime publishDate = DateTime.Now;

    [List(Lazy = false)]
    [Key(1, Column = "NewsItemId")]
    [Index(2, Column = "ImageOrder")]
    [CompositeElement(3, ClassType = typeof(NewsImage))]
   
    public IList<NewsImage> Images
    {
        get { return images; }
        set { images = value; }
    }

    [Property(NotNull = true)]
    public DateTime PublishDate
    {
        get { return publishDate; }
        set { publishDate = value; }
    }

    [Property(NotNull = true)]
    public bool Display { get; set; }
}

[Component]
public class NewsImage : Entity
{
    [Property]
    public string Caption { get; set; }

    [Property()]
    public string Filename { get; set; }

    [Property()]
    public int ImageOrder { get; set; }

    public bool Equals(NewsImage obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        return Equals(obj.Caption, Caption) && Equals(obj.Filename, Filename) && obj.ImageOrder == ImageOrder;
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != typeof (NewsImage)) return false;
        return Equals((NewsImage) obj);
    }

    public override int GetHashCode()
    {
        unchecked
        {
            int result = (Caption != null ? Caption.GetHashCode() : 0);
            result = (result*397) ^ (Filename != null ? Filename.GetHashCode() : 0);
            result = (result*397) ^ ImageOrder;
            return result;
        }
    }
}


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.