gpt4 book ai didi

xml - Grails-Hibernate XML-动态方法

转载 作者:行者123 更新时间:2023-12-02 14:55:26 25 4
gpt4 key购买 nike

我有一个使用Hibernate XML的Grails项目。 Hibernate文件都在conf / hibernate / [DomainName] .hbm.xml中,而匹配的源域文件在src / groovy / [DomainName] .groovy中,我一直在获取:

No signature of method: static com.x.domain.Role.findByAuthority() is applicable for argument types: (java.lang.String)



看起来动态查找器不在类(class)中,尽管我不明白为什么不这样做。有什么建议么?

XML示例:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.x.domain" default-lazy="false">

<class name="Role" table="x_roles" lazy="true">
<cache usage="read-write"/>
<comment>Role</comment>

<id name="id" type="long">
<generator class="native">
</generator>
</id>

<property name="description"/>
<property name="authority"/>

<set name="users" table="x_user_roles" lazy="false">
<cache usage="read-write"/>
<comment>User - Roles Associations</comment>
<key column="role_id"/>
<many-to-many column="user_id" class="com.x.domain.User"/>
</set>
</class>


</hibernate-mapping>

域示例:
package com.x.domain

/**
* Role class for Authority.
*/
class Role {

public static String ROLE_USER = "ROLE_USER"
public static String ROLE_ADMIN = "ROLE_ADMIN"

String description
String authority = 'ROLE_'

Set<User> users = new HashSet<User>();

public Role() {
}

public Role(String description, String authority) {
this.description = description
this.authority = this.authority + authority
}


static constraints = {
authority(blank: false)
description()
}
}

最佳答案

我不确定如何解决该问题,但是回滚到以前的代码可以解决该问题。

关于xml - Grails-Hibernate XML-动态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6500673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com