Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Class inheritance in MongoDB
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kevin Stembridge  
View profile  
 More options Dec 5 2011, 6:44 pm
From: Kevin Stembridge <kevin.stembridge....@gmail.com>
Date: Mon, 5 Dec 2011 15:44:01 -0800 (PST)
Local: Mon, Dec 5 2011 6:44 pm
Subject: Class inheritance in MongoDB
Hi all,
I'm trying to port an existing proof-of-concept written in Java, using
an RDBMS, to Lift using MongoDB. I've never used Lift, Scala or
MongoDB before so its quite a learning curve.

The issue I'm struggling with now is how to implement class
inheritance in MongoDB. In my Java domain model I have the following
classes:
Party
Organization extends Party
Person extends Party
User extends Person

I don't expect to have any trouble modelling these classes in Scala
but I don't know how to then map them to Collections and Documents in
MongoDB. I have seen a tutorial that describes how the C# driver
automatically handles the inheritance for you but there doesn't seem
to be any such functionality in the Java/Scala world.

The reason I'm posting this question in a Lift forum is because I
expect the eventual solution to have something to do with lift-mongodb-
record (at least I would like that to be the case).

Any pointers would be great.

Thanks,
Kevin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IL  
View profile  
 More options Dec 6 2011, 2:37 am
From: IL <iron9li...@gmail.com>
Date: Mon, 5 Dec 2011 23:37:56 -0800 (PST)
Local: Tues, Dec 6 2011 2:37 am
Subject: Re: Class inheritance in MongoDB

lift-mongodb is based on lift-json for this kinda converting job.
So let's think about how to convert it to json.

lift-json support type hints
http://scala-tools.org/mvnsites/liftweb-2.4-M5/#net.liftweb.json.Type...
It's enough for your needs.

Remember that lift-json only support scala case class(and other class with
constructor contains all parameter need to be set. It set values by
constructor but not setter method)

And I think the record api is not good for inheritance, so you should use
lift-mongo or casbah to save and read your converted json objects.

Regards,

IL


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin  
View profile  
 More options Dec 6 2011, 9:12 am
From: Kevin <kevinyp...@gmail.com>
Date: Tue, 6 Dec 2011 06:12:52 -0800 (PST)
Local: Tues, Dec 6 2011 9:12 am
Subject: Re: Class inheritance in MongoDB
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin  
View profile  
 More options Dec 6 2011, 9:14 am
From: Kevin <kevinyp...@gmail.com>
Date: Tue, 6 Dec 2011 06:14:01 -0800 (PST)
Local: Tues, Dec 6 2011 9:14 am
Subject: Re: Class inheritance in MongoDB
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Nelson  
View profile  
 More options Dec 6 2011, 11:03 am
From: Tim Nelson <t...@eltimn.com>
Date: Tue, 6 Dec 2011 08:03:22 -0800 (PST)
Local: Tues, Dec 6 2011 11:03 am
Subject: Re: Class inheritance in MongoDB
Hi Kevin,

Inheritance with Record is a little tricky, but there are some things
you can do, as pointed out in the links in the posts above.

If you'd prefer to use regular case classes then I'd suggest using
Casbah/Salat. Lift has MongoDocument, but Casbah/Salat is more than
likely a better choice. If you go this route you'll lose all of the
features of Record though. In particular, validation and auto form
creation/LiftScreen.

Tim

On Dec 5, 5:44 pm, Kevin Stembridge <kevin.stembridge....@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Stembridge  
View profile  
 More options Jan 26 2012, 4:25 pm
From: Kevin Stembridge <kevin.stembridge....@gmail.com>
Date: Thu, 26 Jan 2012 13:25:29 -0800 (PST)
Local: Thurs, Jan 26 2012 4:25 pm
Subject: Re: Class inheritance in MongoDB
Thank you all for the advice. Looking at the samples in the suggested
links I realise that I don't know enough Scala to understand them. I
think I might have to focus a bit on the basics of the language
first.

On Dec 6 2011, 4:03 pm, Tim Nelson <t...@eltimn.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Stembridge  
View profile  
 More options May 10 2012, 4:27 pm
From: Kevin Stembridge <kevin.stembridge....@gmail.com>
Date: Thu, 10 May 2012 13:27:57 -0700 (PDT)
Local: Thurs, May 10 2012 4:27 pm
Subject: Re: Class inheritance in MongoDB

I've found some time to have another look at my options for mapping class
hierarchies. I checked out Casbah/Salat. But I don't want to give up on
Record just yet because of the extra features that come with it.

When you say its a little tricky, does that mean its impossible? I've been
having a look at the implementation and I think there might be some things
I can try. But my first hurdle is some basic scala stuff. I need to create
my Record classes first of all but I'm getting errors that are related to
type parameterization. I don't know enough Scala to figure out what I need
to do to fix the problem. I'm hoping you guys can help.

Here are a couple of my classes:

class PartyRecord extends MongoRecord[PartyRecord] with UUIDPk[PartyRecord]
{
  def meta = PartyRecord
  object name extends StringField(this, 128)

}

object PartyRecord extends PartyRecord with MongoMetaRecord[PartyRecord]

class OrganizationRecord extends PartyRecord {
  def meta = OrganizationRecord

}

object OrganizationRecord extends OrganizationRecord with
MongoMetaRecord[OrganizationRecord]

OrganizationRecord doesn't compile because it expects the meta method to
return a PartyRecord. So I believe I need to define PartyRecord so that it
is parameterized with an upper bound of PartyRecord.
The class below is is the closest I've come so far to getting something
that compiles but it complains that the value MyType cannot be found.

class PartyRecord[MyType <:PartyRecord[MyType]] extends MongoRecord[MyType]
with UUIDPk[MyType] {
  self: MyType =>
  def meta = PartyRecord
  object name extends StringField(this, 128)

}

object PartyRecord extends PartyRecord[MyType] with
MongoMetaRecord[PartyRecord[MyType]]

I'm hoping this is just a lack of understanding of how type
parameterization works in Scala. Does anyone know what I need to do to get
my type hierarchy to compile?

Cheers,
Kevin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Nelson  
View profile  
 More options May 11 2012, 8:19 am
From: Tim Nelson <tnell...@gmail.com>
Date: Fri, 11 May 2012 05:19:18 -0700 (PDT)
Local: Fri, May 11 2012 8:19 am
Subject: Re: Class inheritance in MongoDB

Hi Kevin,

The problem has more to do with the relationship between MongoRecord and
MongoMetaRecord than type hierarchy. I don't think you'll be able to do it
the way you're trying here. What you can do is the following:

trait BaseRecord[OwnerType <: BaseRecord[OwnerType]] extends
MongoRecord[OwnerType] with UUIDPk[OwnerType] {
  self: OwnerType =>

  object name extends StringField(self, 128)

}

class PartyRecord[OwnerType <: PartyRecord[OwnerType]]
extends BaseRecord[OwnerType] {
  def meta = PartyRecord
}

object PartyRecord extends PartyRecord with MongoMetaRecord[PartyRecord]

class OrganizationRecord[OwnerType <: OrganizationRecord[OwnerType]]
extends BaseRecord[OwnerType] {
  def meta = OrganizationRecord

}

object OrganizationRecord extends OrganizationRecord with
MongoMetaRecord[OrganizationRecord]

Basically, you can't create a concrete MongoRecord class and then extend
that. You can create a trait and extend that, however.

Tim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Stembridge  
View profile  
 More options May 12 2012, 1:38 pm
From: Kevin Stembridge <kevin.stembridge....@gmail.com>
Date: Sat, 12 May 2012 10:38:39 -0700 (PDT)
Local: Sat, May 12 2012 1:38 pm
Subject: Re: Class inheritance in MongoDB

Hi Tim,
Thanks for the response.
I was hoping for better news though. My domain model requires concrete
classes to extend other concrete classes. e.g. PartyRecord -> PersonRecord
-> UserRecord.

I'm going to have to weigh up the trade-offs.

Thanks for the advice.
Kevin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Phelan  
View profile  
 More options May 14 2012, 8:38 pm
From: Ben Phelan <bem...@gmail.com>
Date: Mon, 14 May 2012 17:38:01 -0700 (PDT)
Local: Mon, May 14 2012 8:38 pm
Subject: Re: Class inheritance in MongoDB

Between traits, overriding collectionName, optional fields and Mongo's
schemalessness you can go a long way - or make quite a mess - but it is a
bit of a shame that the kind of thing you want isn't easier here.  There
are lots of advantages to MongoRecord despite the inheritance thing.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »