当我在这两个表之间编写连接查询时,我在两个表之间有多个ToMany关系,加载项目时出错。
以下是查询:
@NamedQueries ({
@NamedQuery(name = "LicenseComponentDefinition.findByProductVerKeyType", query = "SELECT c from LicenseComponentDefinition c join c.licenseKeyTypes lkt WHERE lkt.keyTypeId = :keyTypeId AND WHERE c.product.productId = :productID AND c.productVersionByVersionStartId.versionId <= :versionId AND c.productVersionByVersionEndId.versionId >= :versionId")
})
实体类如下所示
private Set<LicenseKeyType> licenseKeyTypes = new HashSet<LicenseKeyType>(0);
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "component_definition_keytypes", catalog = "ldbredesigned", joinColumns = {
@JoinColumn(name = "component_definition_id", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "license_key_type_id", nullable = false, updatable = false) })
public Set<LicenseKeyType> getLicenseKeyTypes() {
return this.licenseKeyTypes;
}
从查询中删除join子句时,它工作正常。如下所示
SELECT c from LicenseComponentDefinition c WHERE c.product.productId = :productID AND c.productVersionByVersionStartId.versionId <= :versionId AND c.productVersionByVersionEndId.versionId >= :versionId
有人可以帮忙吗? 感谢。
答案 0 :(得分:0)
您的命名查询中包含2个WHERE关键字:
package com.ggl.sudoku.solver.controller;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.JPanel;
import com.ggl.sudoku.solver.view.SudokuFrame;
public class PrintActionListener implements Runnable {
private SudokuFrame frame;
public PrintActionListener(SudokuFrame frame) {
this.frame = frame;
}
@Override
public void run() {
final BufferedImage image = createPanelImage();
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new ImagePrintable(printJob, image));
if (printJob.printDialog()) {
try {
printJob.print();
} catch (PrinterException prt) {
prt.printStackTrace();
}
}
}
private BufferedImage createPanelImage() {
JPanel panel = frame.getSudokuPanel();
BufferedImage image = new BufferedImage(panel.getWidth(),
panel.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
panel.paint(g);
g.dispose();
return image;
}
public class ImagePrintable implements Printable {
private double x, y, width;
private int orientation;
private BufferedImage image;
public ImagePrintable(PrinterJob printJob, BufferedImage image) {
PageFormat pageFormat = printJob.defaultPage();
this.x = pageFormat.getImageableX();
this.y = pageFormat.getImageableY();
this.width = pageFormat.getImageableWidth();
this.orientation = pageFormat.getOrientation();
this.image = image;
}
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex == 0) {
int pWidth = 0;
int pHeight = 0;
if (orientation == PageFormat.PORTRAIT) {
pWidth = (int) Math.min(width, (double) image.getWidth());
pHeight = pWidth * image.getHeight() / image.getWidth();
} else {
pHeight = (int) Math.min(width, (double) image.getHeight());
pWidth = pHeight * image.getWidth() / image.getHeight();
}
g.drawImage(image, (int) x, (int) y, pWidth, pHeight, null);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
}
}
为首发拍摄第二张。