我见过同时实现Comparable和Comparator的类.这是什么意思?为什么我会使用一个而不是另一个?
我在StackOverflow上遇到了一些类似的问题,尝试了解决方案,但没有找到答案.
我使用相当常见的JPA策略来设置某些实体的最后修改时间.设置列和字段,然后标记方法,@PreUpdate并将它们设置为等于当前时间.
问题是我可以在调试器中看到正在调用该方法并且该字段正在更新,但是在我的数据库日志中,我只看到一个SQL调用来更新更改的字段,该字段不包含时间戳字段的UPDATE .
复杂的事情进一步@PrePersist完美,只能@PreUpdate表现出这种行为.
到目前为止,我发现的最接近的解释是在这个LINK.
类似的问题:#1725699和#1745890
我使用EclipseLink v2和JPA v1与GlassFish v2兼容.
我试图直接在Entity类中的方法上使用两个注释,以及使用注释EntityListener附加到Entity类@EntityListener.
我怀疑这是EclipseLink中的一个错误,但我无法证明这一点.
错误与否我非常希望这个简单的操作工作.这个实现有什么问题吗?这是EclipseLink中的已知问题吗?这是JPA中的已知问题吗?有没有解决的办法?
如果没有进入数据库并使用触发器,是否有另一条路径让我的Java代码设置updated_on时间戳?
感谢您的建议!
代码片段如下.
实体字段:
@Column(name = "updated_on")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedOn;
@Column(name = "created_on")
@Temporal(TemporalType.TIMESTAMP)
private Date createdOn;
Run Code Online (Sandbox Code Playgroud)
带注释的更新方法:
@PreUpdate
public void setUpdatedOn(Timestamped object) {
object.setUpdatedOn(new Date());
}
@PrePersist
public void setCreatedOn(Timestamped object) {
if (object.getCreatedOn()==null) {
object.setCreatedOn(new Date());
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个CellTree,它利用MultiSelectionModel和CheckboxCells作为复合单元的一部分.这一切似乎都有效.
我实际上要做的是在我的界面中为可以在树中选择的每个项目生成选项卡.听起来微不足道,但我对如何在selectionChange上获取MyData感到困惑.这些项目需要保持选中状态,这样如果我稍后取消选择它们,则会再次删除这些选项卡.
我需要获取刚刚选择的项目的MyData,以便知道选项卡的内容应该是什么.
final MultiSelectionModel<TableLight> selectionModel = new MultiSelectionModel<TableLight>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
}
});
Run Code Online (Sandbox Code Playgroud)
我觉得我完全错过了那个明显的东西.我在selectionChange事件中所能做的就是询问我的选择处理程序以查看所选集合是什么.有没有办法可以将监听器附加到特定的树选择而不是全局,"有些东西已经改变"的监听器.
任何提示都将非常感激.
我目前正在研究gwt web app,它已接近完成,但现在我在将项目调试为Web应用程序时收到以下警告:
Jan 10, 2012 5:13:55 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed greetServlet: java.lang.NullPointerException
Jan 10, 2012 5:13:55 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Failed startup of context com.google.appengine.tools.development.DevAppEngineWebAppContext@29ef4453{/,/home/ich/Eclipse Workspace/Mein Wochenplaner/war}
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:191)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:239)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:146)
at com.google.appengine.tools.development.gwt.AppEngineLauncher.start(AppEngineLauncher.java:97)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Jan 10, 2012 5:13:55 PM …Run Code Online (Sandbox Code Playgroud) 我创建了简单的gui应用程序,JFilechooser用于打开pdf文件.gui有一个浏览按钮和一个textArea来可视化文件的内容.
我创建了两个类:Gui(包含main())和GuiJFrame来实现gui,处理程序和监听器.我设法获得了窗口应用程序,但浏览按钮似乎不起作用.我不知道我哪里弄错了,请帮帮我
import java.awt.EventQueue;
public class Gui {
/** Launch the application. */
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Gui window = new Gui();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/** Create the application. */
public Gui() {
initialize();
}
/** Initialize the contents of the frame. */
private void initialize() {
GuiJFrame guiJFrame = new GuiJFrame();
guiJFrame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring和Hibernate,并且我成功地在Service类的构造函数内自动装配了一个Repository.当我尝试在我的Service类中添加方法时,我得到的是关于CGLib类的生成.@TransactionalAopConfigException
我的配置包含3个文件.一个AppInitializer实现类WebApplicationInitializer,一个WebMvcConfig扩展类WebMvcConfigurerAdapter和最后一PersistentContext类.
AppInitializer
public class AppInitializer implements WebApplicationInitializer {
private static final String CONFIG_LOCATION = "com.project.app.config";
private static final String MAPPING_URL = "/";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping(MAPPING_URL);
}
private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(CONFIG_LOCATION);
return context;
}
Run Code Online (Sandbox Code Playgroud)
WebMvcConfig …
我使用Spring和Hibernate和我想的是,为了是必要的,“线”类的Autowire一库一内部服务。
Repository 类扩展了 CrudRepository
停止存储库
@Repository
@RepositoryRestResource(collectionResourceRel = "stop", path = "stop")
public interface StopRepository extends CrudRepository<StopJPA, Long> {
StopJPA findById(@Param("id") Long id);
StopJPA findByIdStop(@Param("idStop") String idStop);
@Override
void delete(StopJPA deleted);
@Override
List<StopJPA> findAll();
// Optional<StopJPA> findOne(Long id);
@Override
StopJPA findOne(Long id);
@Override
StopJPA save(StopJPA persisted);
void flush();
}
Run Code Online (Sandbox Code Playgroud)
实体类。
停止JPA
@Entity
@Table(name = "stop")
@EntityListeners(RepoListener.class)
public class StopJPA implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = …Run Code Online (Sandbox Code Playgroud) 使用计时器我checkBookings()反复调用插槽.我能够编译并运行程序,但在执行上述FOR循环时崩溃了.
错误:"在QList :: at中ASSERT失败:"索引超出范围",文件../../../../Qt/2010.05/qt/include/QtCore/../../src/corelib /tools/qlist.h,第455行传递给C运行时函数的参数无效.传递给C运行时函数的参数无效."
我的代码是:
timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(checkBookings()));
timer->start(500000);
void Canvas::checkBookings()
{
QString dateStr;
for(int i= 0;i<=qlist.count();i++)
{
dateStr = qList.at(i).at(6);
}
}
Run Code Online (Sandbox Code Playgroud) java ×5
gwt ×2
spring ×2
cglib ×1
comparable ×1
comparator ×1
debugging ×1
eclipselink ×1
events ×1
hibernate ×1
indexing ×1
jfilechooser ×1
jpa ×1
qlist ×1
qt ×1
qtimer ×1
selection ×1
spring-aop ×1
swing ×1
tree ×1