我在单表中有父/子关系,让我们说就像这样简单
id | parent_id | some_data
Run Code Online (Sandbox Code Playgroud)
我试图理解/实现如何为单表关系构建Hibernate类的最佳实践.
我有一个来自某个地方的源,它有嵌套的JSON结构,因此在解析之后我想在OracleDB中使用它.
饲料看起来像
{
1:
=> 2:
=> 3
=> 4:
=> 5
=> 6
}
Run Code Online (Sandbox Code Playgroud)
这些数据最终应该在db中:
1 | 0 (main rec, no parent)
2 | 1
3 | 2
4 | 2
5 | 4
6 | 1
Run Code Online (Sandbox Code Playgroud)
它可以越走越深......
我想遍历JSON结构并构建最终保存在db中的类
session.save(parent)
Run Code Online (Sandbox Code Playgroud)
parent将是我的hibernate映射类的实例,让我们将其命名为Feed.
每次我下降树时,它都会创建一个新的Feed,找到它的父级并将其添加到列表中.
Feed **parent** = new Feed();
-> Feed child2 = new Feed();
child2.setParent(parent)
parent.add(child2);
-> Feed child3 = new Feed();
child3.setParent(child2)
child2.add(child3);
Feed child4 = new Feed();
child4.setParent(child2)
child2.add(child4);
.............
session.save(**parent**) …Run Code Online (Sandbox Code Playgroud) 我想听选项卡中发生的所有时间轴事件,我创建了一个扩展程序
chrome.browserAction.onClicked.addListener(function(tab) {
var tabId = tab.id;
console.log("tabId = ", tabId);
if (running === false) {
checkAvailable();
chrome.debugger.attach({
tabId: tabId
}, protocolVersion, function() {
running = true;
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
chrome.debugger.sendCommand({
tabId: tabId
}, "Tracing.start", { "maxCallStackDepth" : 5 }, function(response) {
console.log(response);
// listening for responses from Timeline
chrome.debugger.onEvent.addListener(function(tabId, method, params) {
console.log("params = ", params);
});
});
chrome.debugger.onDetach.addListener(function (source, reason) {
running = false;
});
});
} else {
chrome.debugger.detach({
tabId: tabId
}, null);
running …Run Code Online (Sandbox Code Playgroud) 是否可以将值从父对象传播到嵌套对象的集合?例如
DTO源类
class CarDTO {
private String name;
private long userId;
private Set<WheelDto> wheels;
};
class WheelDto {
private String name;
}
Run Code Online (Sandbox Code Playgroud)
目标实体类别
class Car {
private String name;
private long userId;
private Set<Wheel> wheels;
};
class Wheel {
private String name;
private long lastUserId;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在WheelDto上没有lastUserId,因此我想在我尝试过的wheels集合中的每个对象上将CarDto的userId映射到WheelDto的lastUserId。
@Mapping(target = "wheels.lastUserId", source = "userId")
Run Code Online (Sandbox Code Playgroud)
但没有运气
我需要编写正则表达式,只允许数字,像&|这样的字符 .()和空格.
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
List<String> input = new ArrayList<String>();
input.add("(0.4545 && 0.567) || 456"); // should PASS
input.add("9876-5-4321");
input.add("987-65-4321 (attack)");
input.add("(0.4545 && 0.567) || 456 && (me)");
input.add("0.456 && 0.567"); // should PASS
for (String ssn : input) {
boolean f = ssn.matches("^[\\d\\s()&|.]$");
if (f) {
System.out.println("Found good …Run Code Online (Sandbox Code Playgroud) 我发现了一种改造的方法,List<Object> to a Map<Integer, Object>但我需要
List<Object> to Map<Integer, List<Object>
Run Code Online (Sandbox Code Playgroud)
比如我上课了
class Movie {
public int rank;
public String desc;
public Movie(int rank, String desc) {
this.rank = rank;
this.desc = desc;
}
}
Run Code Online (Sandbox Code Playgroud)
并列出:
List<Movie> movies = new ArrayList<Movie>();
movies.add(new Movie(1, "The Movie 0"));
movies.add(new Movie(2, "The Movie 1"));
movies.add(new Movie(2, "The Movie 2"));
Run Code Online (Sandbox Code Playgroud)
我想要的是每个等级的列表地图..
List<Movie> -> Map<Integer (rank), List<Movie>>
Run Code Online (Sandbox Code Playgroud)
与番石榴我可以做这样的简单转换
Map<Integer,Movie> mappedMovies = Maps.uniqueIndex(movies, new Function <Movie,Integer> () {
public Integer apply(Movie from) {
return from.getRank();
}}); …Run Code Online (Sandbox Code Playgroud) 尝试使用时区将UNIX时间戳转换为Oracle时间戳.期望看到不同的输出,但是datetime部分是相同的.
什么是拧?
select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('EST') from dual;
Run Code Online (Sandbox Code Playgroud)
产出:27-FEB-08 09.21.56 .656000000 AM -05:00
select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('PST') from dual;
Run Code Online (Sandbox Code Playgroud)
产出:27-FEB-08 09.21.56 .656000000 AM -07:00
为什么日期/时间部分是一样的?Oracle不做调整吗?