Does anyone have any examples of how you're stitching together scala and hibernate? I'm looking for the most basic of basics; an example scala domain class and how the hibernate mapping works with it, or something at least at that level.
On Dec 19, 2007, at 4:13 AM, Michael Campbell wrote:
> Does anyone have any examples of how you're stitching together scala > and hibernate?
I'd like to see this too... especially in the wiki!
> I'm looking for the most basic of basics; an example > scala domain class and how the hibernate mapping works with it, or > something at least at that level.
> I'm looking for the most basic of basics; an example > > scala domain class and how the hibernate mapping works with it, or > > something at least at that level.
> Does anyone have any examples of how you're stitching together scala
> and hibernate? I'm looking for the most basic of basics; an example
> scala domain class and how the hibernate mapping works with it, or
> something at least at that level.
> On Dec 19, 6:13 am, "Michael Campbell" <michael.campb......@gmail.com>
> wrote:
> > Does anyone have any examples of how you're stitching together scala
> > and hibernate? I'm looking for the most basic of basics; an example
> > scala domain class and how the hibernate mapping works with it, or
> > something at least at that level.
> On Dec 19, 2007, at 4:13 AM, Michael Campbell wrote:
> > Does anyone have any examples of how you're stitching together scala
> > andhibernate?
> I'd like to see this too... especially in the wiki!
> > I'm looking for the most basic of basics; an example
> > scala domain class and how thehibernatemapping works with it, or
> > something at least at that level.
> > On Dec 19, 2007, at 4:13 AM, Michael Campbell wrote:
> > > Does anyone have any examples of how you're stitching together scala > > > andhibernate?
> > I'd like to see this too... especially in the wiki!
> > > I'm looking for the most basic of basics; an example > > > scala domain class and how thehibernatemapping works with it, or > > > something at least at that level.
I am Scala beginner, so sorry about the basic question...
I wonder why in withTxSession, you use:
val r = f(s) // builds the function t.commit // commits the session r // executes the function
and not f(s) // executes the function with the session as a parameter t.commit // commits the session and save the obejcts created/updated in the function
Also, I thought that hibernate .jar included all the other jars but I can't check it at the moment.
Thanks
Fred
On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote:
> Hi Steve,
> I am Scala beginner, so sorry about the basic question...
> I wonder why in withTxSession, you use:
> val r = f(s) // builds the function
> t.commit // commits the session
> r // executes the function
> and not
> f(s) // executes the function with the session as a parameter
> t.commit // commits the session and save the obejcts created/updated in the
> function
Hi Fred, I read it like this...
val r = f(s) // calls the function or callback f, saving the result
in variable r
t.commit // commits the transaction
r // returns the result that came from f
> Also, I thought that hibernate .jar included all the other jars but I can't
> check it at the moment.
You might be right. I didn't check that myself, but followed the
Hibernate tutorial and kept on adding jar files until the compiler
stopped complaining. Real teeth gritting trying to parse a durn
simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
My system for Hibernate+Scala was that persisted classes would have an associated Actor DAO that they are tied to by a trait. This gives each instance of an object a "save" and "delete" function. The Actor DAOs were written so that they inherited (and could override) CRUD operations. It was a pretty nifty system. There was also a bunch of utility functions to aid searching and common operations. It was quite simple to setup new database objects. I also had an ant file that controlled an empty rails project so I could use migrations and model generation to help manage the SQL side and (if I wanted to go that far) generate hibernate mappings. I've gotten permission to release this stuff into the wild if you guys think it's worth exploring.
On Jan 25, 2008 12:56 AM, steve.yen <steve....@gmail.com> wrote:
> On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote: > > Hi Steve,
> > I am Scala beginner, so sorry about the basic question...
> > I wonder why in withTxSession, you use:
> > val r = f(s) // builds the function > > t.commit // commits the session > > r // executes the function
> > and not > > f(s) // executes the function with the session as a parameter > > t.commit // commits the session and save the obejcts created/updated in the > > function
> Hi Fred, I read it like this...
> val r = f(s) // calls the function or callback f, saving the result > in variable r > t.commit // commits the transaction > r // returns the result that came from f
> > Also, I thought that hibernate .jar included all the other jars but I can't > > check it at the moment.
> You might be right. I didn't check that myself, but followed the > Hibernate tutorial and kept on adding jar files until the compiler > stopped complaining. Real teeth gritting trying to parse a durn > simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
> Thanks, > Steve
> > Thanks
> > Fred
> > On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
> > > Hi, I wrote up an single file example, here, of using Scala and > > > Hibernate...
Daniel Green,
I'm certainly eager to explore it. But docs with include plenty of
context help me to not be confused. The sample files you had
would be one of the most useful things for those who learn by
doing.
Johnnie
On Jan 26, 10:05 am, "Daniel Green" <october...@gmail.com> wrote:
> My system for Hibernate+Scala was that persisted classes would have an
> associated Actor DAO that they are tied to by a trait. This gives
> each instance of an object a "save" and "delete" function. The Actor
> DAOs were written so that they inherited (and could override) CRUD
> operations. It was a pretty nifty system. There was also a bunch of
> utility functions to aid searching and common operations. It was quite
> simple to setup new database objects. I also had an ant file that
> controlled an empty rails project so I could use migrations and model
> generation to help manage the SQL side and (if I wanted to go that
> far) generate hibernate mappings. I've gotten permission to release
> this stuff into the wild if you guys think it's worth exploring.
> On Jan 25, 2008 12:56 AM, steve.yen <steve....@gmail.com> wrote:
> > On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote:
> > > Hi Steve,
> > > I am Scala beginner, so sorry about the basic question...
> > > I wonder why in withTxSession, you use:
> > > val r = f(s) // builds the function
> > > t.commit // commits the session
> > > r // executes the function
> > > and not
> > > f(s) // executes the function with the session as a parameter
> > > t.commit // commits the session and save the obejcts created/updated in the
> > > function
> > Hi Fred, I read it like this...
> > val r = f(s) // calls the function or callback f, saving the result
> > in variable r
> > t.commit // commits the transaction
> > r // returns the result that came from f
> > > Also, I thought that hibernate .jar included all the other jars but I can't
> > > check it at the moment.
> > You might be right. I didn't check that myself, but followed the
> > Hibernate tutorial and kept on adding jar files until the compiler
> > stopped complaining. Real teeth gritting trying to parse a durn
> > simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
> > Thanks,
> > Steve
> > > Thanks
> > > Fred
> > > On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
> > > > Hi, I wrote up an single file example, here, of using Scala and
> > > > Hibernate...
> My system for Hibernate+Scala was that persisted classes would have an > associated Actor DAO that they are tied to by a trait. This gives > each instance of an object a "save" and "delete" function. The Actor > DAOs were written so that they inherited (and could override) CRUD > operations. It was a pretty nifty system. There was also a bunch of > utility functions to aid searching and common operations. It was quite > simple to setup new database objects. I also had an ant file that > controlled an empty rails project so I could use migrations and model > generation to help manage the SQL side and (if I wanted to go that > far) generate hibernate mappings. I've gotten permission to release > this stuff into the wild if you guys think it's worth exploring.
> On Jan 25, 2008 12:56 AM, steve.yen <steve....@gmail.com> wrote:
> > On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote: > > > Hi Steve,
> > > I am Scala beginner, so sorry about the basic question...
> > > I wonder why in withTxSession, you use:
> > > val r = f(s) // builds the function > > > t.commit // commits the session > > > r // executes the function
> > > and not > > > f(s) // executes the function with the session as a parameter > > > t.commit // commits the session and save the obejcts created/updated > in the > > > function
> > Hi Fred, I read it like this...
> > val r = f(s) // calls the function or callback f, saving the result > > in variable r > > t.commit // commits the transaction > > r // returns the result that came from f
> > > Also, I thought that hibernate .jar included all the other jars but I > can't > > > check it at the moment.
> > You might be right. I didn't check that myself, but followed the > > Hibernate tutorial and kept on adding jar files until the compiler > > stopped complaining. Real teeth gritting trying to parse a durn > > simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
> > Thanks, > > Steve
> > > Thanks
> > > Fred
> > > On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
> > > > Hi, I wrote up an single file example, here, of using Scala and > > > > Hibernate...
I rewrote allot of stuff and I haven't tested my rewrites yet (allot of this was written in this email) but here's a general idea of the stuff I was doing. Note that I assume that I can parametrize Class. I did this here so I could unclutter my examples.
There was a base actor for all actors servicing a class:
abstract class ServiceActor[T](val servicedClass : Class[T]) extends Actor { override def act { loop { react { provide } } }
def provide : PartialFunction[Any,Unit] def services(f : PartialFunction[Any,Unit]) = f
}
so if i wanted to implement CRUD operations I'd first write a convenience trait:
trait CRUDServices[T <: POSO] { val serviceActor : CRUDService[T]
class CRUDService[T <: POSO](servicedClass : Class[T]) extends ServiceActor[T](servicedClass) with CRUDServices { override val serviceActor = this
override def provide = services { case Save(poso) => reply { transact((s, t) => s.save(poso)) poso.id } case Delete(poso) => reply(transact((s,t) => s.delete(poso))) case Get(id) => reply { transact { (s,t) => val poso = s.load(servicedClass, id).asInstanceOf[T] Hibernate.initialize(poso) poso.id = id poso } } }
}
and now for... THE END RESULT!
If I just wanted an instance of a generic crud service to manage a class I could:
val service = new CRUDService(classOf[User]) service.start service.delete(user)
or if I needed to batch a mass delete of users and then move on to do other stuff:
users.foreach(service ! Delete(_))
Or if I wanted to get fancy and implement some non-crud operations or override crud operations:
// This will need to be started before it can be used object UserService extends CRUDService(classOf[User]) { override def provide = services { case GetFriends(id) => reply(/*...*/) case Delete(poso) => reply(/* overrides generic delete */) } orElse super.provide
}
and that's all you need to do stuff like
UserService.delete(user) // or val user = UserService.get(id)
This is a really cool system and you can wire it to do some very fun stuff. With Terracotta integration it is even better. In my POSO (plain old scala object) trait I have tie ins to crud operations so I can do stuff like
user.delete // and user.save
I've also written a bunch of hibernate utilities for searching, paginating, etc.
On Jan 27, 2008 2:33 AM, Fred Janon <fja...@gmail.com> wrote:
> It would be great if you release it. I would love to look at it.
> Thanks for sharing
> Fred
> On 1/27/08, Daniel Green <october...@gmail.com> wrote:
> > My system for Hibernate+Scala was that persisted classes would have an > > associated Actor DAO that they are tied to by a trait. This gives > > each instance of an object a "save" and "delete" function. The Actor > > DAOs were written so that they inherited (and could override) CRUD > > operations. It was a pretty nifty system. There was also a bunch of > > utility functions to aid searching and common operations. It was quite > > simple to setup new database objects. I also had an ant file that > > controlled an empty rails project so I could use migrations and model > > generation to help manage the SQL side and (if I wanted to go that > > far) generate hibernate mappings. I've gotten permission to release > > this stuff into the wild if you guys think it's worth exploring.
> > On Jan 25, 2008 12:56 AM, steve.yen <steve....@gmail.com> wrote:
> > > On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote: > > > > Hi Steve,
> > > > I am Scala beginner, so sorry about the basic question...
> > > > I wonder why in withTxSession, you use:
> > > > val r = f(s) // builds the function > > > > t.commit // commits the session > > > > r // executes the function
> > > > and not > > > > f(s) // executes the function with the session as a parameter > > > > t.commit // commits the session and save the obejcts created/updated > in the > > > > function
> > > Hi Fred, I read it like this...
> > > val r = f(s) // calls the function or callback f, saving the result > > > in variable r > > > t.commit // commits the transaction > > > r // returns the result that came from f
> > > > Also, I thought that hibernate .jar included all the other jars but I > can't > > > > check it at the moment.
> > > You might be right. I didn't check that myself, but followed the > > > Hibernate tutorial and kept on adding jar files until the compiler > > > stopped complaining. Real teeth gritting trying to parse a durn > > > simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
> > > Thanks, > > > Steve
> > > > Thanks
> > > > Fred
> > > > On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
> > > > > Hi, I wrote up an single file example, here, of using Scala and > > > > > Hibernate...
> I rewrote allot of stuff and I haven't tested my rewrites yet (allot > of this was written in this email) but here's a general idea of the > stuff I was doing. Note that I assume that I can parametrize Class. I > did this here so I could unclutter my examples.
> There was a base actor for all actors servicing a class:
> abstract class ServiceActor[T](val servicedClass : Class[T]) extends Actor > { > override def act { > loop { > react { > provide > } > } > }
> def provide : PartialFunction[Any,Unit] > def services(f : PartialFunction[Any,Unit]) = f > }
> so if i wanted to implement CRUD operations I'd first write a convenience > trait:
> class CRUDService[T <: POSO](servicedClass : Class[T]) extends > ServiceActor[T](servicedClass) with CRUDServices { > override val serviceActor = this
> If I just wanted an instance of a generic crud service to manage a > class I could:
> val service = new CRUDService(classOf[User]) > service.start > service.delete(user)
> or if I needed to batch a mass delete of users and then move on to do > other stuff:
> users.foreach(service ! Delete(_))
> Or if I wanted to get fancy and implement some non-crud operations or > override crud operations:
> // This will need to be started before it can be used > object UserService extends CRUDService(classOf[User]) { > override def provide = services { > case GetFriends(id) => reply(/*...*/) > case Delete(poso) => reply(/* overrides generic delete */) > } orElse super.provide > }
> and that's all you need to do stuff like
> UserService.delete(user) > // or > val user = UserService.get(id)
> This is a really cool system and you can wire it to do some very fun > stuff. With Terracotta integration it is even better. In my POSO > (plain old scala object) trait I have tie ins to crud operations so I > can do stuff like
> user.delete > // and > user.save
> I've also written a bunch of hibernate utilities for searching, > paginating, etc.
> On Jan 27, 2008 2:33 AM, Fred Janon <fja...@gmail.com> wrote: > > Hi Daniel,
> > It would be great if you release it. I would love to look at it.
> > Thanks for sharing
> > Fred
> > On 1/27/08, Daniel Green <october...@gmail.com> wrote:
> > > My system for Hibernate+Scala was that persisted classes would have an > > > associated Actor DAO that they are tied to by a trait. This gives > > > each instance of an object a "save" and "delete" function. The Actor > > > DAOs were written so that they inherited (and could override) CRUD > > > operations. It was a pretty nifty system. There was also a bunch of > > > utility functions to aid searching and common operations. It was quite > > > simple to setup new database objects. I also had an ant file that > > > controlled an empty rails project so I could use migrations and model > > > generation to help manage the SQL side and (if I wanted to go that > > > far) generate hibernate mappings. I've gotten permission to release > > > this stuff into the wild if you guys think it's worth exploring.
> > > On Jan 25, 2008 12:56 AM, steve.yen <steve....@gmail.com> wrote:
> > > > On Jan 24, 8:46 pm, "Fred Janon" <fja...@gmail.com> wrote: > > > > > Hi Steve,
> > > > > I am Scala beginner, so sorry about the basic question...
> > > > > I wonder why in withTxSession, you use:
> > > > > val r = f(s) // builds the function > > > > > t.commit // commits the session > > > > > r // executes the function
> > > > > and not > > > > > f(s) // executes the function with the session as a parameter > > > > > t.commit // commits the session and save the obejcts > created/updated > > in the > > > > > function
> > > > Hi Fred, I read it like this...
> > > > val r = f(s) // calls the function or callback f, saving the > result > > > > in variable r > > > > t.commit // commits the transaction > > > > r // returns the result that came from f
> > > > > Also, I thought that hibernate .jar included all the other jars > but I > > can't > > > > > check it at the moment.
> > > > You might be right. I didn't check that myself, but followed the > > > > Hibernate tutorial and kept on adding jar files until the compiler > > > > stopped complaining. Real teeth gritting trying to parse a durn > > > > simple XML string into a org.w3c.dom.Document! dom4j? sax? meh.
> > > > Thanks, > > > > Steve
> > > > > Thanks
> > > > > Fred
> > > > > On Jan 25, 2008 12:27 PM, steve.yen <steve....@gmail.com> wrote:
> > > > > > Hi, I wrote up an single file example, here, of using Scala and > > > > > > Hibernate...
-- _____________________________________ / \ /lift/ committer (www.liftweb.net) SGS member (Scala Group Sweden) SEJUG member (Swedish Java User Group) \_____________________________________/