当你使用spring和Hibernate时,你有没有遇到过日志警告
警告o.hibernate.ejb.HibernatePersistence - HHH015016:遇到了一个弃用的javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; 请改用[org.hibernate.jpa.HibernatePersistenceProvider].
怎么处理?谢谢你的回答.
我正在玩简单的重载覆盖规则并发现一些有趣的东西.这是我的代码.
package com.demo;
public class Animal {
private void eat() {
System.out.println("animal eating");
}
public static void main(String args[]) {
Animal a = new Horse();
a.eat();
}
}
class Horse extends Animal {
public void eat() {
System.out.println("Horse eating");
}
}
Run Code Online (Sandbox Code Playgroud)
该程序输出如下.
动物吃
这就是我所知道的:
private void eat()方法,它不一定会在子类中访问,因此这里不会出现方法覆盖的问题,因为JLS明确定义了它.public void eat()从Horse类调用方法Animal a = new Horse();因多态性而有效.为什么a.eat()要从Animal类中调用方法?我们正在创建一个Horse对象,为什么要调用Animal类的方法呢?
如果它存在于静态内部类中,如何执行main方法?
main方法存在于静态内部类中,我们需要执行该main方法.
class A {
static class B {
public static void main(String[] args) {
System.out.println("Done");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我编写了java程序,在ArrayList中添加整数并从ArrayList中删除该整数.但它没有给我正确的结果.这是我的代码..
public static void main(String args[])
{
ArrayList<Integer> a=new ArrayList<Integer>();
a.add(6);
a.add(7);
a.add(8);
a.add(9);
for(int i=0;i<=a.size();i++)
{
System.out.println("Removed Elements=>"+a.remove(i));
}
}
Run Code Online (Sandbox Code Playgroud)
它给我输出如下
Removed Elements=>6
Removed Elements=>8
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.remove(ArrayList.java:387)
at CollectionTemp.main(CollectionTemp.java:19)
Run Code Online (Sandbox Code Playgroud)
为什么我得到这样的输出?
public class Product implements Serializable{
private String id;
private String name;
private double price ;
private int quantity;
public Product(String id, String name, double price, int quantity) {
this.id = id;
this.name = name;
this.price = price;
this.quantity = quantity;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
} …Run Code Online (Sandbox Code Playgroud) 这是一个理论问题.我只是好奇,如果Java有一个垃圾收集机制来释放内存,那么为什么还会OutOfMemoryError发生呢?
我搜索了这个,但可以得到这些链接
垃圾收集器是否保证在Out of Memory Error之前运行?
这些没有具体回答我的问题.如果Java通过使用垃圾收集很好地允许内存,那么为什么会OutOfMemoryError发生呢?
我有关于jpa查询的问题.有两个表,即Post表和Tag表Post和Tag之间有很多关系
现在我想编写一个查询,以便在选择多个标签时,应选择与这些标签关联的所有帖子.例如,
post1 has tags friends and motivation
post2 has tags motivation and pune
post3 has tag boxing
Run Code Online (Sandbox Code Playgroud)
如果选择标签friends和pune,那么如果选择标签装箱则应检索post1和post2,那么如果选择标签装箱和动机则应检索第3位,则应检索所有三个位置.
我试过跟踪的事情
SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags IN :tags
Run Code Online (Sandbox Code Playgroud)
但它给出了验证器错误
The state field path 'p.tags' cannot be resolved to a collection type.
Run Code Online (Sandbox Code Playgroud)
如果我这样试试
SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags = :tags
Run Code Online (Sandbox Code Playgroud)
然后它符合要求但在传递标签列表后会出错
java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter tags with expected type of …Run Code Online (Sandbox Code Playgroud) 有谁知道该group_skip怎么办?
也许它是一个基本的编程,但我已经使用Java编程了几年,今天才发现它.
group_skip: do {
event = stepToNextEvent(FormController.STEP_OVER_GROUP);
switch (event) {
case FormEntryController.EVENT_QUESTION:
case FormEntryController.EVENT_END_OF_FORM:
break group_skip;
}
} while (event != FormEntryController.EVENT_END_OF_FORM);
Run Code Online (Sandbox Code Playgroud)
谢谢!
我遇到了一个真正让我感到困惑的问题。我想用 JUL 日志(JDK 日志)尝试一些东西。我从以下简单程序开始:
package biz.ple;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class Application {
public static void main(String[] args)
{
Logger logA = LogManager.getLogManager().getLogger("LoggerA");
Logger logB = LogManager.getLogManager().getLogger("LoggerB");
if (logA == null) {
System.out.println("LoggerA is null!");
}
if (logB == null) {
System.out.println("LoggerB is null!");
}
String normalMsg = "Message without cookie prefix.";
String cookieMsg = "[Cookie] Message with a cookie prefix.";
logA.info(normalMsg);
logA.info(cookieMsg);
logB.info(normalMsg);
logB.info(cookieMsg);
}
}
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,记录器 logA 和 logB始终为空。我在文档中读到应用程序没有强引用的记录器我随时都会被 GC,但在我看来变量 logA 和 logB 确实是强引用,不是吗?
我真的不明白这一点,希望得到任何帮助。
我知道这个问题并不是非常具体的编程,但我试图在wildfly或jboss 7.1中的standalone.xml中找到每个标签的描述,以便我可以了解每个标签,这对配置很有帮助.
在哪里可以找到描述standalone.xml中使用的标签的文档?jBoss或Wildfly管理指南未提供所有信息.
java ×9
break ×1
eclipselink ×1
hibernate ×1
jboss7.x ×1
jpa ×1
jpa-2.0 ×1
jpql ×1
loops ×1
oop ×1
overriding ×1
polymorphism ×1
sorting ×1
spring ×1
wildfly ×1