问题
I've just started using Play Framework. After I finished tutorials (covering basic functions) I try setup connection between database and play. One of my relations has schema:
CREATE TABLE IF NOT EXISTS `shop`.`CatPath` (
`parentC` INT NOT NULL ,
`childC` INT NOT NULL ,
`depth` INT NOT NULL ,
PRIMARY KEY (`parentC`, `childC`)
)
so I built model's class:
@Entity
public class CatPath extends Model {
@EmbeddedId
public CatPathKey key;
public Long depth;
public class CatPathKey {
public Long parentC;
public Long childC;
}
public static Finder<CatPathKey, CatPath> find = new Finder<CatPathKey, CatPath>(CatPathKey.class, CatPath.class);
after compilation I get exception:
PersistenceException: Could not find BeanDescriptor for class models.CatPath$KatPathKey. Perhaps the EmbeddedId class is not registered?
I don't know where is a problem, when I followed tutorials everything worked. Only difference between my code and tutorial's is key: I have compound key, in tutorials only one column makes key. Why in tutorials 'registering class' wasn't necessary? I guess, it was registered automatically but why now, with compound key, it isn't?
I tried to find some information, I found: http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/EmbeddedId this xml code is 'class registering'? In Play framework tutorials and detailed topics xml isn't mentioned, I didn't do anything with my model's classes and everything worked.
回答1:
You have to add the @Embeddable
annotation under your CatPathKey
class:
@Embeddable
public class CatPathKey {
public Long parentC;
public Long childC;
}
来源:https://stackoverflow.com/questions/14030937/compound-key-in-ebean-and-play-framework