我在Hibernate中表示对象层次结构时遇到了一些麻烦.我一直在搜索,并没有设法找到这样或类似的任何例子 - 如果这是一个常见问题,你有道歉.
我有两种类型,我想继续使用Hibernate:Groups和Items.
*通过名称和父母的组合唯一地识别组.
*这些组被安排在许多树中,这样每个组都有零个或一个父组.
*每个项目可以是零个或多个组的成员.
理想情况下,我想要一个双向关系,允许我得到:
*所有组,其中一个项目是
*所有项目的成员,所有项目是特定组或其后代的成员.
我还需要能够从顶部遍历组树,以便在UI上显示它.
理想情况下,基本对象结构如下所示:
class Group {
...
/** @return all items in this group and its descendants */
Set<Item> getAllItems() { ... }
/** @return all direct children of this group */
Set<Group> getChildren() { ... }
...
}
class Item {
...
/** @return all groups that this Item is a direct member of */
Set<Group> getGroups() { ... }
...
}
Run Code Online (Sandbox Code Playgroud)
最初,我刚刚在Items和Groups之间建立了一个简单的双向多对多关系,这样获取组层次结构中的所有项目都需要在树中递归,并且为Item获取组是一个简单的getter,即:
class Group {
...
private Set<Item> items; …Run Code Online (Sandbox Code Playgroud) 我有一个使用Hibernate进行数据持久化的应用程序,其中Spring处于最佳状态(很好的衡量标准).直到最近,应用程序中还有一个持久化类,A:
@Entity
public class A {
@Id
@Column(unique = true, nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
public String name;
}
Run Code Online (Sandbox Code Playgroud)
我已经添加了A的子类,称为B:
@Entity
public class B extends A {
public String description;
}
Run Code Online (Sandbox Code Playgroud)
添加B后,我现在无法加载A. 抛出以下异常:
class org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException :: Object with id: 1 was not of the specified subclass: A (Discriminator: null); nested exception is org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: A (Discriminator: null)
Run Code Online (Sandbox Code Playgroud)
我将以下注释和属性添加到B,它似乎已经解决了问题.这是解决问题的正确方法吗?
...
@DiscriminatorFormula("(CASE WHEN dtype IS NULL …Run Code Online (Sandbox Code Playgroud) 我编写了一个只应在特定线程上调用的方法.是否有标准注释或注释应添加到方法的javadoc中以表示这一点?
可能重复:
如何动态合并两个JavaScript对象的属性?
如果我有两个Javascript对象,我将其用作键值对列表:
var a = {a:1};
var b = {b:2};
Run Code Online (Sandbox Code Playgroud)
将它们组合成包含两者属性的第三个对象的最有效方法是什么?
var c = {a:1, b:2};
Run Code Online (Sandbox Code Playgroud)
如果一个或两个我不介意a,并b在此过程中被修改.
它们是否有任何潜在问题(安全性、性能)或与使用System.getProperty()/System.setProperty()在 Java 中存储应用程序范围的变量相关的普遍不良情绪?
如何使用命令行中的antrun-plugin运行特定目标?
mvn antrun:run 不会让它运行.
<project>
...
<build>
<plugins>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>myExecution</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant target="myTarget" inheritRefs="true">
...
</ant>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
...
</dependencies>
</plugin>
...
</plugins>
...
</build>
...
</project>
Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法从Grails中的远程服务器获取JSON数据集?
例如,数据 http://example.com/data.json
数据:
{
"firstName": "John",
"lastName": "Smith"
}
Run Code Online (Sandbox Code Playgroud)
示例Groovy代码(理论):
def data = getJson('http://example.com/data.json')
println data.firstName // this will print "John"
Run Code Online (Sandbox Code Playgroud) 我有一个sqlite数据库,其中我有一个我想要在webview中加载的内容,因为我想从数据库中选择并在Web视图中显示,有没有办法这样做?
public class TataworatYawmeeh extends Activity {
WebView webView;
String javascrips;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tataworat);
webView = (WebView) findViewById(R.id.tatworatWebView);
webView.setBackgroundColor(0x00000000);
try {
DataBaseHelper myDbHelper = new DataBaseHelper(this);
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDataBase();
String selectQuery = "SELECT * FROM 'nnn'";
SQLiteDatabase db = myDbHelper.getReadableDatabase();
db.execSQL(selectQuery);
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
}
} …Run Code Online (Sandbox Code Playgroud) 我想将 gradle 存储库与我的build.gradle文件中的特定配置联系起来,例如:
repositories {
testCompile {
mavenCentral()
}
compile {
maven { url 'https://vetted-repo.example.com' }
}
}
Run Code Online (Sandbox Code Playgroud)
我无法从 gradle 文档中找到执行此操作的简单方法。我需要编写自己的插件吗?