我有课
class DateOptTimeType implements org.hibernate.usertype.UserType
适用于两列
@org.hibernate.annotations.Type(type = "com.mmyPack.DateOptTimeType")
@org.hibernate.annotations.Columns(columns = {
@javax.persistence.Column(name = "DATE1"),
@javax.persistence.Column(name = "FLAG")
}) protected DateOptTime dateOfDeath;
Run Code Online (Sandbox Code Playgroud)
我可以这样做,该类也可以使用1列(包含1列和2列),例如
@javax.persistence.Column(name = "DATE1"),
protected DateOptTime dateOfDeath;
Run Code Online (Sandbox Code Playgroud) 我正在使用maven 创建.ear
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>wsformatter-ear</finalName>
<includeLibInApplicationXml>true</includeLibInApplicationXml>
<version>1.4</version>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
.ear中的所有依赖项看起来像joda-time-1.6.2.jar,commons-io-1.4.jar等.
但是,我有依赖,我想要没有版本.例如,我该怎么做,依赖slf4j-api-1.5.6.jar在我的.ear中看起来像slf4j-api.jar
我来吧,我有桌子
USER
-id:long
-login:varchar
-weapon:varchar
-magic:varchar
我希望将这个表映射到两个类(使用Hibernate/JPA)
class Mag
{
long id;
String login;
String weapon;
}
Run Code Online (Sandbox Code Playgroud)
和
class Warrior
{
long id;
String login;
String magic;
}
Run Code Online (Sandbox Code Playgroud)
如果我发送HQL查询:SELECT m FROM Mag m WHERE m.login = ?然后我得到Mag实例
,如果我发送HQL查询:SELECT w FROM Warrior w WHERE w.login = ?然后我得到Warrior实例
我尝试做这样的事情
@Entity
@Table(name = "User")
class User
{
long id;
String login;
}
@Entity
class Mag extends User
{
String magic;
}
@Entity
class Warrior extends User
{
String weapon; …Run Code Online (Sandbox Code Playgroud) public class Main {
public static void main(String[] args){
System.out.println(X.Y.Z);
}
}
class X {
static class Y {
static String Z = "Result 1";
}
static C Y = new C();
}
class C {
String Z = "Result 2";
}
Run Code Online (Sandbox Code Playgroud)
有时输出是"Result 1",有时输出是"Result 2".你能解释一下原因吗?
我在用JDK 1.6_33.
我在一个字符串中有用户的名字和姓氏,例如
John Doe
Peter Smithon
现在我想把这个字符串转换为两个字符串 - firstname和lastname
John Doe- > first = John,last = Doe
John- > first = John,last =""
[space]Doe- > first ="",last = Doe.
我正在使用下一个代码
var fullname = "john Doe"
var last = fullname.replace(/^.*\s/, "").toUpperCase().trim(); // john
var first = fullname.replace(/\s.*$/, "").toUpperCase().trim(); // Doe
Run Code Online (Sandbox Code Playgroud)
这适用于双字全名.但如果全名有一个字,那我就有问题了
var fullname = "john"
var last = fullname.replace(/^.*\s/, "").toUpperCase().trim(); // john
var first = fullname.replace(/\s.*$/, "").toUpperCase().trim(); // john
Run Code Online (Sandbox Code Playgroud)
我使用Java EE 5,EJB 3.0,Jboss AS 4.3.2.
我有最简单的Stateful豆子
@Local
public interface IStateBean
{
}
@Stateful
public class StateBean implements IStateBean
{
private static int number = 0;
@PostConstruct
void init()
{
number++;
System.out.println("@PostConstruct: " + number);
}
@PreDestroy
void destroy()
{
number--;
System.out.println("@PreDestroy: " + number);
}
}
Run Code Online (Sandbox Code Playgroud)
我在servlet中查找这个bean
public class MyServlet extends HttpServlet
{
@Override
public void doGet(final HttpServletRequest aRequest, final HttpServletResponse aResponse) throws ServletException, IOException
{
IStateBean bean = new InitialContext().lookup("app-ear/StateBean/local"); …Run Code Online (Sandbox Code Playgroud) 我有跟随鼠标光标的图像。
HTML:
<img id="cow" src="https://icons.iconarchive.com/icons/gakuseisean/ivista-2/128/Alarm-Arrow-Right-icon.png" height="30px" width="30px" style="position: absolute; top: 50%; left: 50%;"/>
Run Code Online (Sandbox Code Playgroud)
Javascript:
var mouseXY = {};
$( document ).on( "mousemove", function( event ) {
mouseXY.X = event.pageX;
mouseXY.Y = event.pageY;
});
var iCow = $("#cow");
var cowInterval = setInterval(function()
{
var cowXY = iCow.position();
var diffX = cowXY.left - mouseXY.X;
var diffY = cowXY.top - mouseXY.Y;
var newX = cowXY.left - diffX / 1000;
var newY = cowXY.top - diffY / 1000;
iCow.css({left: newX, top: newY});
}, 10); …Run Code Online (Sandbox Code Playgroud) 让我有桌子(书籍和作者有很多关系)
BOOKS
id
book_name
作者
id
author_name
BOOKS_AUTHORS
id
book_id
author_id
我将这些表映射到实体上
class Books
{
@Id
long id;
@Column(name = "author_name")
String name;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "BOOKS_AUTHORS",
joinColumns = @JoinColumn(name = "book_id"),
inverseJoinColumns = @JoinColumn(name = "author_id"))
List<Authots> authors;
// setter, getters, adder
}
class Authors
{
@Id
long id;
@Column(name = "author_name")
String name;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "BOOKS_AUTHORS",
joinColumns = @JoinColumn(name = "author_id"),
inverseJoinColumns = @JoinColumn(name = "book_id"))
List<Books> …Run Code Online (Sandbox Code Playgroud) 可能重复:
我们如何使用Hibernate计算行数?
我想按数据库中的条件计算记录数.
我尝试使用下一个查询
String queryString = "SELECT Count(*) FROM my_table";
Query query = entityManager.createNativeQuery(queryString);
Run Code Online (Sandbox Code Playgroud)
但没有方法可以执行此操作Query query并获得结果.
我知道,我可以使用记录来计算记录
String queryString = "SELECT * FROM my_table";
Query query = entityManager.createNativeQuery(queryString);
query.getResultList().size();
Run Code Online (Sandbox Code Playgroud)
所以问题,是查询具有Count(*)更多性能,如果yes,那么如何执行查询Count(*)?
我有这个代码
@Local
interface IRepo
{ //...
}
@Stateless
class Repo implements IRepo
{ // ..
}
class WebS
{
@EJB private IRepo repo;
// ...
}
Run Code Online (Sandbox Code Playgroud)
一切正常.
但现在我删除界面 IRepo和制作
@Stateless
class Repo { // ..
}
class WebS
{
@EJB private Repo repo;
// ...
}
Run Code Online (Sandbox Code Playgroud)
和JNDI查找失败.
could not resolve global JNDI name for @EJB for container WebS ...
Run Code Online (Sandbox Code Playgroud)
我可以在没有接口的情况下进行依赖注入吗?