有谁可以说我的申请有什么问题?
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
public boolean insertUser(User user) {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
} catch (HibernateException he) {
session.getTransaction().rollback();
return false;
}finally{
if (session != null){
session.close();
}
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是我调用在数据库中插入用户的唯一方法,然后如果我尝试插入另一个,则启动此异常:
Initial SessionFactory creation …Run Code Online (Sandbox Code Playgroud) 我开发了这个联系表格:
<!DOCTYPE html>
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
<h:panelGrid columns="3">
<h:outputLabel for="name" value="Nome (Obrigatório)" />
<h:inputText id="name" value="#{contact.client.name}" />
<h:message for="name" />
<h:outputLabel for="email" value="E-Mail (Obrigatório)" />
<h:inputText id="email" value="#{contact.client.email}" />
<h:message for="email" />
<h:outputLabel for="website" value="Website (Opcional)" />
<h:inputText id="website" value="#{contact.client.website}" />
<h:message for="website" />
</h:panelGrid>
<h:outputLabel for="text" value="Mensagem (Obrigatório):" /> <br/>
<h:inputTextarea id="text" value="#{contact.client.text}" rows="20" cols="80" /><br/>
<h:message for="text" />
<br/>
<h:commandButton value="Enviar" action="#{contact.sendMessage}" >
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:outputText value="#{contact.messageStatus}" id="out" />
<a4j:status> …Run Code Online (Sandbox Code Playgroud) 我试图在View模式中使用Open Session,但是每当我试图捕捉到EntityManager我ManagedBean的entityManager到来时NULL我就是这样做的:
package filters;
// imports..
public class JPAFilter implements Filter {
private EntityManagerFactory factory;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
EntityManager entityManager = this.factory.createEntityManager();
request.setAttribute("entityManager", entityManager);
entityManager.getTransaction().begin();
chain.doFilter(request, response);
try {
entityManager.getTransaction().commit();
} catch (Exception e) {
entityManager.getTransaction().rollback();
throw new ServletException(e);
} finally {
entityManager.close();
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
this.factory = Persistence.createEntityManagerFactory("copadomundo");
}
@Override
public void destroy() { …Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有JPA的JSF网站.所以我在Glassfish实例和我的项目中配置了一个DataSource.
但我想知道,如何在Eclipse中测试我的JPA查询?
例如,在Netbeans中,您只需右键单击该hibernate.cfg文件并"运行HQL查询"(翻译)Eclipse中有类似的内容吗?
更新: 在评论之后我安装了Hibernate Tools然后尝试使用HQL编辑器,但下面给出了这个奇怪的错误:


知道怎么解决这个问题?
为了让自己清楚,这是我的JPA配置:

更新2: 我做了@kenChan推荐的但似乎我还有一个错误:(我不知道我必须将MySQL驱动程序放在类路径中,在Hibernate Tools配置中,tkanks KenChan.)
错误:

更新3: @KenChan我试图创建一个属性文件(我在这里发现了类似的问题),但仍然给出了同样的错误:


更新4: 它的工作原理!
在这一行的最后,我错过了一个人:
hibernate.connection.provider_class
Run Code Online (Sandbox Code Playgroud)
最后我的hibernate.properties保持这种方式:
hibernate.connection.password=***********
hibernate.connection.username=*******
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.url=jdbc\:mysql\://********\:3306/********
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=
hibernate.cache.use_query_cache=false
Run Code Online (Sandbox Code Playgroud)
谢谢@KenChan的支持.
我有以下脚本来创建表autolife.log:
CREATE TABLE `log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`idpoint` int(11) NOT NULL,
`value` varchar(10) NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `fk_point_id` (`idpoint`),
CONSTRAINT `fk_point_id` FOREIGN KEY (`idpoint`) REFERENCES `point` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=155562 DEFAULT CHARSET=latin2$$
Run Code Online (Sandbox Code Playgroud)
所以我使用JPA ToolsEclipse Indigo中的表创建实体:
@Entity
public class Log implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="LOG_ID_GENERATOR", sequenceName="SEQUENCE_KEY")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="LOG_ID_GENERATOR")
private Integer …Run Code Online (Sandbox Code Playgroud) 我试图创建一个马赛克,它很简单:

delete当用户hover超过图像时我正在考虑显示按钮.但我的网站也响应,所以只悬停不起作用,我需要在用户点击图像上方时显示按钮.
我发现这个代码做了悬停部分,(我对CSS很糟糕,对不起)我怎么能以简单的方式做到这一点?
更新
抱歉误会的人.我认为智能手机没有这个hover功能,因此用户在点击图片时会显示一个删除图像的按钮,如果他按下它,图像就会被移除,这就是我的意思.
我经常需要编辑一些代码(在编辑器中),然后在项目结构中工作.我想用键盘而不是鼠标在这两者之间切换.我怎么能在PyCharm中做到这一点?

我想将VARCHAR转换为INT,但在我的表中我有一些像'???'的值 然后SQL Server启动此expcetion:
Conversion failed when converting the varchar value '????' to data type int.
Severity 16
Run Code Online (Sandbox Code Playgroud)
我可以转换这个'???' 为NULL,这没问题,但是怎么做?
我正在尝试做这样的事情:
INSERT INTO labbd11..movie(title, year)
SELECT movies.title,
CASE movies.mvyear IS '????' THEN NULL ELSE CAST (movies.mvyear AS INT)
FROM disciplinabd..movies
Run Code Online (Sandbox Code Playgroud)
但没有任何作用..
有什么想法吗?
我在密码验证方面遇到了一些问题,@ BalusC 在这里帮助我.但是在我在表单中插入验证代码后,当我调用控制器方法时,没有任何反应.这是我的JSF页面:Register.xhtml
<!DOCTYPE html>
<html lang="pt-br"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head>
<title>TITLE</title>
</h:head>
<h:body>
<h:form id="form">
<h:panelGrid columns="3" >
<h:outputLabel for="name" value="Nome:" />
<h:inputText id="name" value="#{register.person.name}" >
<f:ajax event="blur" listener="#{register.validateName}" render="m_name" />
</h:inputText>
<rich:message id="m_name" for="name" ajaxRendered="false"/>
// some fields ..
<h:outputLabel for="password" value="Password" />
<h:inputSecret id="password" value="#{register.user.password}">
<f:validator validatorId="confirmPasswordValidator" />
<f:attribute name="confirm" value="#{confirmPassword.submittedValue}" />
<f:ajax event="blur" execute="password confirm" render="m_password" />
</h:inputSecret>
<rich:message id="m_password" for="password" />
<h:outputLabel for="confirm" value="Senha (novamente):" />
<h:inputSecret id="confirm" binding="#{confirmPassword}" >
<f:ajax …Run Code Online (Sandbox Code Playgroud) 我是新来的ActiveMQ。我有 2 queues:parser-queue和generation-queue. 我的应用程序在2 个不同的服务器上运行,两者都在侦听队列。我的工作流程非常简单,从解析器队列获取消息,处理它并在工作完成后将另一条消息放入生成队列。
但是,如果在我的工作过程中,获取消息并处理它,我的应用程序将关闭,或者由于任何原因而中断。
未正确处理的同一消息如何再次发送到我的队列以进行处理?
我正在阅读有关订阅恢复策略的内容,但这似乎是一个非常复杂的主题,我不确定是否要使用基于时间的策略,因为我的工作可能会随着时间的推移而变化以完全由我的应用程序处理。
java ×3
jpa ×3
jsf-2 ×3
css ×2
eclipse ×2
hibernate ×2
jpa-2.0 ×2
jsf ×2
case ×1
casting ×1
css3 ×1
database ×1
exception ×1
glassfish-3 ×1
image ×1
java-ee ×1
javascript ×1
jms ×1
mysql ×1
netbeans ×1
pc ×1
pycharm ×1
richfaces ×1
spring ×1
spring-jms ×1
sql ×1
sql-server ×1
validation ×1
windows ×1