[Lift] Re: JPA is killing me. Enumeration hell.

2009-01-22 Thread Jorge Ortiz
I don't really know much about JPA, but just a quick observation on the code
you posted:

Your code has line:
  abstract class EnumvType(val et: Enumeration with EnumTrait) extends
UserType {
whereas JPA Demo has line:
  abstract class EnumvType(val et: Enumeration with Enumv) extends UserType
{

I don't know what your EnumTrait is, or whether it might be causing the
problem, but it's worth noting.

One thing I can do is release a version of 0.10 that compiles against Scala
2.7.2 and rolls back the minor changes made to Lift to compile against
2.7.2. But I don't know how David et al feel about this.

--j

On Thu, Jan 22, 2009 at 3:16 PM, Charles F. Munat c...@munat.com wrote:


 I have an entity thus:

 @Entity
 @Table{val name = cocktails}
 class Cocktail extends BaseEntity {
   @Id
   @GeneratedValue{val strategy = GenerationType.AUTO}
   var id : Long = _

   var name : String = 

   var description : String = 

   var ingredients : String = 

   @Column{val name = file_name}
   var fileName : String = 

   @Column{val name = is_archived}
   var isArchived : Boolean = false

   @Type{val `type` = com.xxx.model.CocktailGroupType}
   @Column{val name=cocktail_group}
   var cocktailGroup: CocktailGroup.Value = CocktailGroup.Originals
 }



 Which uses this enumeration:

 object CocktailGroup extends Enumeration with Enumv {
   val Originals = Value(Originals)
   val Contemporaries = Value(Contemporaries)
   val Classics = Value(Classics)
   val Others = Value(Others)
 }

 class CocktailGroupType extends EnumvType(CocktailGroup) {}



 Which is queried thus in orm.xml:

 named-query name=findCocktailsByGroup
   query![CDATA[from Cocktail c
 where c.isArchived = false
 and c.cocktailGroup = :cocktailGroup
 order by c.name]]/query
 /named-query



 And called from CocktailOps.scala:

 120: val cocktails = Model.createNamedQuery[Cocktail](
findCocktailsByGroup,
cocktailGroup - Originals).findAll



 Using Enumv:

 trait Enumv  {

   this: Enumeration =

   private var nameDescriptionMap =
 scala.collection.mutable.Map[String, String]()

   def Value(name: String, desc: String) : Value = {
 nameDescriptionMap += (name - desc)
 new Val(name)
   }

   def getDescriptionOrName(ev: this.Value) = {
 try {
   nameDescriptionMap(+ev)
 } catch {
   case e: NoSuchElementException = ev.toString
 }
   }

   def getNameDescriptionList =  this.elements.toList.map(
 v = (v.toString, getDescriptionOrName(v) ) ).toList
 }



 And EnumvType:

 abstract class EnumvType(val et: Enumeration with EnumTrait)
   extends UserType {

   val SQL_TYPES = Array({Types.VARCHAR})

   override def sqlTypes() = SQL_TYPES

   override def returnedClass = classOf[et.Value]

   override def equals(x: Object, y: Object): Boolean = {
 return x == y
   }

   override def hashCode(x: Object) = x.hashCode

   override def nullSafeGet(resultSet: ResultSet,
names: Array[String],
owner: Object): Object = {
 val value = resultSet.getString(names(0))
 if (resultSet.wasNull()) return null
 else {
   return et.valueOf(value)
 }
   }

   override def nullSafeSet(statement: PreparedStatement,
value: Object,
index: Int): Unit = {
 if (value == null) {
   statement.setNull(index, Types.VARCHAR)
 } else {
   val en = value.toString
   statement.setString(index, en)
 }
   }

   override def deepCopy(value: Object): Object = value

   override def isMutable() = false

   override def disassemble(value: Object) =
 value.asInstanceOf[Serializable]

   override def assemble(cached: Serializable, owner: Object):
 Serializable = cached

   override def replace(original: Object,
target: Object,
owner: Object) = original

 }


 Which gets me this error:

 Exception occured while processing /drinks/

 Message: javax.persistence.PersistenceException:
 org.hibernate.PropertyAccessException: could not set a field value by
 reflection setter of com.xxx.model.Cocktail.cocktailGroup

  
 org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
com.xxx.model.ScalaQuery.getResultList(JPA.scala:82)
com.xxx.model.ScalaQuery.findAll(JPA.scala:77)
com.xxx.snippet.CocktailOps.originals(CocktailOps.scala:120)




 I have tried everything I can think of. This used to work before the
 recent switch to 2.7.3. Can anyone spot the problem?

 Thanks. Website down. Am really screwed here.

 Chas.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 

[Lift] Re: JPA is killing me. Enumeration hell.

2009-01-22 Thread David Pollak
On Thu, Jan 22, 2009 at 4:05 PM, Jorge Ortiz jorge.or...@gmail.com wrote:

 I don't really know much about JPA, but just a quick observation on the
 code you posted:

 Your code has line:
   abstract class EnumvType(val et: Enumeration with EnumTrait) extends
 UserType {
 whereas JPA Demo has line:
   abstract class EnumvType(val et: Enumeration with Enumv) extends UserType
 {

 I don't know what your EnumTrait is, or whether it might be causing the
 problem, but it's worth noting.

 One thing I can do is release a version of 0.10 that compiles against Scala
 2.7.2 and rolls back the minor changes made to Lift to compile against
 2.7.2. But I don't know how David et al feel about this.


As long as it doesn't muck up the mainline 0.10 stuff in scala-tools.org,
I'm cool with it.




 --j


 On Thu, Jan 22, 2009 at 3:16 PM, Charles F. Munat c...@munat.com wrote:


 I have an entity thus:

 @Entity
 @Table{val name = cocktails}
 class Cocktail extends BaseEntity {
   @Id
   @GeneratedValue{val strategy = GenerationType.AUTO}
   var id : Long = _

   var name : String = 

   var description : String = 

   var ingredients : String = 

   @Column{val name = file_name}
   var fileName : String = 

   @Column{val name = is_archived}
   var isArchived : Boolean = false

   @Type{val `type` = com.xxx.model.CocktailGroupType}
   @Column{val name=cocktail_group}
   var cocktailGroup: CocktailGroup.Value = CocktailGroup.Originals
 }



 Which uses this enumeration:

 object CocktailGroup extends Enumeration with Enumv {
   val Originals = Value(Originals)
   val Contemporaries = Value(Contemporaries)
   val Classics = Value(Classics)
   val Others = Value(Others)
 }

 class CocktailGroupType extends EnumvType(CocktailGroup) {}



 Which is queried thus in orm.xml:

 named-query name=findCocktailsByGroup
   query![CDATA[from Cocktail c
 where c.isArchived = false
 and c.cocktailGroup = :cocktailGroup
 order by c.name]]/query
 /named-query



 And called from CocktailOps.scala:

 120: val cocktails = Model.createNamedQuery[Cocktail](
findCocktailsByGroup,
cocktailGroup - Originals).findAll



 Using Enumv:

 trait Enumv  {

   this: Enumeration =

   private var nameDescriptionMap =
 scala.collection.mutable.Map[String, String]()

   def Value(name: String, desc: String) : Value = {
 nameDescriptionMap += (name - desc)
 new Val(name)
   }

   def getDescriptionOrName(ev: this.Value) = {
 try {
   nameDescriptionMap(+ev)
 } catch {
   case e: NoSuchElementException = ev.toString
 }
   }

   def getNameDescriptionList =  this.elements.toList.map(
 v = (v.toString, getDescriptionOrName(v) ) ).toList
 }



 And EnumvType:

 abstract class EnumvType(val et: Enumeration with EnumTrait)
   extends UserType {

   val SQL_TYPES = Array({Types.VARCHAR})

   override def sqlTypes() = SQL_TYPES

   override def returnedClass = classOf[et.Value]

   override def equals(x: Object, y: Object): Boolean = {
 return x == y
   }

   override def hashCode(x: Object) = x.hashCode

   override def nullSafeGet(resultSet: ResultSet,
names: Array[String],
owner: Object): Object = {
 val value = resultSet.getString(names(0))
 if (resultSet.wasNull()) return null
 else {
   return et.valueOf(value)
 }
   }

   override def nullSafeSet(statement: PreparedStatement,
value: Object,
index: Int): Unit = {
 if (value == null) {
   statement.setNull(index, Types.VARCHAR)
 } else {
   val en = value.toString
   statement.setString(index, en)
 }
   }

   override def deepCopy(value: Object): Object = value

   override def isMutable() = false

   override def disassemble(value: Object) =
 value.asInstanceOf[Serializable]

   override def assemble(cached: Serializable, owner: Object):
 Serializable = cached

   override def replace(original: Object,
target: Object,
owner: Object) = original

 }


 Which gets me this error:

 Exception occured while processing /drinks/

 Message: javax.persistence.PersistenceException:
 org.hibernate.PropertyAccessException: could not set a field value by
 reflection setter of com.xxx.model.Cocktail.cocktailGroup

  
 org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
com.xxx.model.ScalaQuery.getResultList(JPA.scala:82)
com.xxx.model.ScalaQuery.findAll(JPA.scala:77)
com.xxx.snippet.CocktailOps.originals(CocktailOps.scala:120)




 I have tried everything I can think of. This used to work before the
 recent switch to 2.7.3. Can anyone spot the problem?

 Thanks. Website down. Am really screwed here.

 Chas.




 



-- 
Lift, the simply functional web framework http://liftweb.net
Collaborative Task 

[Lift] Re: JPA is killing me. Enumeration hell.

2009-01-22 Thread Jorge Ortiz
Ahh, I see what the problem might be. There was another change to EnumvType:

Replace this line:
  return et.valueOf(value)
With this line:
  return et.valueOf(value).getOrElse(null)

I'm sorry this is causing you so much trouble Chas. I made changes to
classes in JPADemo and didn't realize they were used as template code for
other projects.

Perhaps these classes should be rolled into a lift-jpa module so that
everyone can share the same code?

--j

On Thu, Jan 22, 2009 at 3:16 PM, Charles F. Munat c...@munat.com wrote:


 I have an entity thus:

 @Entity
 @Table{val name = cocktails}
 class Cocktail extends BaseEntity {
   @Id
   @GeneratedValue{val strategy = GenerationType.AUTO}
   var id : Long = _

   var name : String = 

   var description : String = 

   var ingredients : String = 

   @Column{val name = file_name}
   var fileName : String = 

   @Column{val name = is_archived}
   var isArchived : Boolean = false

   @Type{val `type` = com.xxx.model.CocktailGroupType}
   @Column{val name=cocktail_group}
   var cocktailGroup: CocktailGroup.Value = CocktailGroup.Originals
 }



 Which uses this enumeration:

 object CocktailGroup extends Enumeration with Enumv {
   val Originals = Value(Originals)
   val Contemporaries = Value(Contemporaries)
   val Classics = Value(Classics)
   val Others = Value(Others)
 }

 class CocktailGroupType extends EnumvType(CocktailGroup) {}



 Which is queried thus in orm.xml:

 named-query name=findCocktailsByGroup
   query![CDATA[from Cocktail c
 where c.isArchived = false
 and c.cocktailGroup = :cocktailGroup
 order by c.name]]/query
 /named-query



 And called from CocktailOps.scala:

 120: val cocktails = Model.createNamedQuery[Cocktail](
findCocktailsByGroup,
cocktailGroup - Originals).findAll



 Using Enumv:

 trait Enumv  {

   this: Enumeration =

   private var nameDescriptionMap =
 scala.collection.mutable.Map[String, String]()

   def Value(name: String, desc: String) : Value = {
 nameDescriptionMap += (name - desc)
 new Val(name)
   }

   def getDescriptionOrName(ev: this.Value) = {
 try {
   nameDescriptionMap(+ev)
 } catch {
   case e: NoSuchElementException = ev.toString
 }
   }

   def getNameDescriptionList =  this.elements.toList.map(
 v = (v.toString, getDescriptionOrName(v) ) ).toList
 }



 And EnumvType:

 abstract class EnumvType(val et: Enumeration with EnumTrait)
   extends UserType {

   val SQL_TYPES = Array({Types.VARCHAR})

   override def sqlTypes() = SQL_TYPES

   override def returnedClass = classOf[et.Value]

   override def equals(x: Object, y: Object): Boolean = {
 return x == y
   }

   override def hashCode(x: Object) = x.hashCode

   override def nullSafeGet(resultSet: ResultSet,
names: Array[String],
owner: Object): Object = {
 val value = resultSet.getString(names(0))
 if (resultSet.wasNull()) return null
 else {
   return et.valueOf(value)
 }
   }

   override def nullSafeSet(statement: PreparedStatement,
value: Object,
index: Int): Unit = {
 if (value == null) {
   statement.setNull(index, Types.VARCHAR)
 } else {
   val en = value.toString
   statement.setString(index, en)
 }
   }

   override def deepCopy(value: Object): Object = value

   override def isMutable() = false

   override def disassemble(value: Object) =
 value.asInstanceOf[Serializable]

   override def assemble(cached: Serializable, owner: Object):
 Serializable = cached

   override def replace(original: Object,
target: Object,
owner: Object) = original

 }


 Which gets me this error:

 Exception occured while processing /drinks/

 Message: javax.persistence.PersistenceException:
 org.hibernate.PropertyAccessException: could not set a field value by
 reflection setter of com.xxx.model.Cocktail.cocktailGroup

  
 org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
com.xxx.model.ScalaQuery.getResultList(JPA.scala:82)
com.xxx.model.ScalaQuery.findAll(JPA.scala:77)
com.xxx.snippet.CocktailOps.originals(CocktailOps.scala:120)




 I have tried everything I can think of. This used to work before the
 recent switch to 2.7.3. Can anyone spot the problem?

 Thanks. Website down. Am really screwed here.

 Chas.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JPA is killing me. Enumeration hell.

2009-01-22 Thread Charles F. Munat

Thank you! Thank you! Thank you! Thank you! Thank you!

That worked. I should've seen it though as I'd already made that fix on 
other sites. I don't know how I missed it. Tired, I guess.

Pressure off now for a moment at least.

Chas.

Jorge Ortiz wrote:
 Ahh, I see what the problem might be. There was another change to EnumvType:
 
 Replace this line:
   return et.valueOf(value)
 With this line:
   return et.valueOf(value).getOrElse(null)
 
 I'm sorry this is causing you so much trouble Chas. I made changes to 
 classes in JPADemo and didn't realize they were used as template code 
 for other projects.
 
 Perhaps these classes should be rolled into a lift-jpa module so that 
 everyone can share the same code?
 
 --j
 
 On Thu, Jan 22, 2009 at 3:16 PM, Charles F. Munat c...@munat.com 
 mailto:c...@munat.com wrote:
 
 
 I have an entity thus:
 
 @Entity
 @Table{val name = cocktails}
 class Cocktail extends BaseEntity {
   @Id
   @GeneratedValue{val strategy = GenerationType.AUTO}
   var id : Long = _
 
   var name : String = 
 
   var description : String = 
 
   var ingredients : String = 
 
   @Column{val name = file_name}
   var fileName : String = 
 
   @Column{val name = is_archived}
   var isArchived : Boolean = false
 
   @Type{val `type` = com.xxx.model.CocktailGroupType}
   @Column{val name=cocktail_group}
   var cocktailGroup: CocktailGroup.Value = CocktailGroup.Originals
 }
 
 
 
 Which uses this enumeration:
 
 object CocktailGroup extends Enumeration with Enumv {
   val Originals = Value(Originals)
   val Contemporaries = Value(Contemporaries)
   val Classics = Value(Classics)
   val Others = Value(Others)
 }
 
 class CocktailGroupType extends EnumvType(CocktailGroup) {}
 
 
 
 Which is queried thus in orm.xml:
 
 named-query name=findCocktailsByGroup
   query![CDATA[from Cocktail c
 where c.isArchived = false
 and c.cocktailGroup = :cocktailGroup
 order by c.name http://c.name]]/query
 /named-query
 
 
 
 And called from CocktailOps.scala:
 
 120: val cocktails = Model.createNamedQuery[Cocktail](
findCocktailsByGroup,
cocktailGroup - Originals).findAll
 
 
 
 Using Enumv:
 
 trait Enumv  {
 
   this: Enumeration =
 
   private var nameDescriptionMap =
 scala.collection.mutable.Map[String, String]()
 
   def Value(name: String, desc: String) : Value = {
 nameDescriptionMap += (name - desc)
 new Val(name)
   }
 
   def getDescriptionOrName(ev: this.Value) = {
 try {
   nameDescriptionMap(+ev)
 } catch {
   case e: NoSuchElementException = ev.toString
 }
   }
 
   def getNameDescriptionList =  this.elements.toList.map(
 v = (v.toString, getDescriptionOrName(v) ) ).toList
 }
 
 
 
 And EnumvType:
 
 abstract class EnumvType(val et: Enumeration with EnumTrait)
   extends UserType {
 
   val SQL_TYPES = Array({Types.VARCHAR})
 
   override def sqlTypes() = SQL_TYPES
 
   override def returnedClass = classOf[et.Value]
 
   override def equals(x: Object, y: Object): Boolean = {
 return x == y
   }
 
   override def hashCode(x: Object) = x.hashCode
 
   override def nullSafeGet(resultSet: ResultSet,
names: Array[String],
owner: Object): Object = {
 val value = resultSet.getString(names(0))
 if (resultSet.wasNull()) return null
 else {
   return et.valueOf(value)
 }
   }
 
   override def nullSafeSet(statement: PreparedStatement,
value: Object,
index: Int): Unit = {
 if (value == null) {
   statement.setNull(index, Types.VARCHAR)
 } else {
   val en = value.toString
   statement.setString(index, en)
 }
   }
 
   override def deepCopy(value: Object): Object = value
 
   override def isMutable() = false
 
   override def disassemble(value: Object) =
 value.asInstanceOf[Serializable]
 
   override def assemble(cached: Serializable, owner: Object):
 Serializable = cached
 
   override def replace(original: Object,
target: Object,
owner: Object) = original
 
 }
 
 
 Which gets me this error:
 
 Exception occured while processing /drinks/
 
 Message: javax.persistence.PersistenceException:
 org.hibernate.PropertyAccessException: could not set a field value by
 reflection setter of com.xxx.model.Cocktail.cocktailGroup
  
  
 org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)