I am using Scala to type JPA2 criteria questions. So I have a Java metamold class (my code has only Java, balance scale -> Pure Scala problem), which holds my model attributes:
@StaticMetamodel (User.class) Public class user_ [public stable volatile cingular attribute & lt; User, long & gt; Id; Public static volatile Cingular attributes & lt; User, string & gt; Name; } To perform a query for a single feature, I have this function:
def findByAttribute [T] (attribute: cingular attribute [ User, T], Value: T): Arrayist [user] = {...} How can I call it:
UserEJB.findByAttribute (User_Name, "John") I am now trying to create a query function, with which I can query for many features at once, And that's why I One parameter for my function is to use the map of the organizer:
// map type scala.collection.immutable.Map def findByAttributes [T] (Features: Map [SingularAttribute [User , T], T]: ArrayList [user] = {...} OK, so the function should work ... but how can I call it ??? Say for example, I would like to ask a map like this:
User_.name -> "doo" User_.id -> 5 So my first method is to define this map in Scala and pass it to find it:
val criteria = map (User_.name - & Gt; "DO", user_id.id -> 5) // creates compiler error val users = userEJB.findByAttributes Unfortunately, the compiler is not satisfied while passing the finder FindByAttributes-function, generating error below Is:
No type parameter for method findByAttributes: (Attributes: map [javax.persistence.metamodel.SingularAttribute [net.teachernews.model.User, T], T]) java.util .ArrayList [net.teachernews.model.User] exists so that it can be applied on logic (scala.collection.immutable.Map [javax.preistence.metamodel.quickularAttribute [net.teachernews.model. Gaar, _ & gt;: java.lang.String with java.lang.Long & lt ;: java.lang.Comparable [_>: java.lang.String with java.lang.Long and lt;: java. Lang.Comparable [java.lang.String with java.lang.Long & lt ;: java.io.Serializable] java.io.Serializable] with Java.io.Serializable], any]) --- Because --- the type of argument expression is not consistent with the formal parameter type; Found: scala.collection.immutable.map [javax.preistence.metamodel.SingularAttribute [net.teachernews.model.User, _>: java.lang.Long with java.lang.String & lt;: java.lang .comparable [_ & Gt ;: java.lang.String with java.lang.Long & lt ;: java.lang.Comparable [_ & gt ;: java.lang.String with java.lang.Long & lt;: Java.io.Serializable] with Java .a.Serializable] with java.io.Serializable], any] required: map [javax.preistence.metamodel.SingularAttribute [net.teachernews.model.User ,? T], T] This is the most complex generic problem I've ever had. A little too much for my skill;) Anyone knows how to create the right map type which I can pass through the function? Is it possible, or what compiler can not explain anymore type in my case? Or am I using the wrong datastructure?
I have not prepared the details completely, but I think some way
< Pre> type attributewallpayer [t] = pair [cngular attribute [user, t], t] df search byvivalpare [t] (p: attribute valuepair [t]): Arriylist [user] = findBatrite P._1, p ._2) def findByAttributes (attributes: attributeValuePair [_] *): ArrayList [user] = {...} may be a call then
findByAttributes (User_.name - & gt; "D O ", User_.id -> 5) EDIT: Edit: to identify with my negligence in Scala 2.8 REPL findByAttributeValuePair The method may be required to receive a call at the findByAttribute .
Comments
Post a Comment