如何通过Hibernate + Java

时间:2016-10-17 04:56:30

标签: java postgresql hibernate

我有一个Java Web Applicaiton(struts2,hibernate,beans)+ PostreSQL作为DB。任务是将base64编码的文本保存在某个特定表的数据库中。从base64文件生成pdf,然后使用特定算法ciphered生成pdfText个文件< 1mb,大部分< 300kb。

我进行了搜索,并建议将base64保存为数据库中的Model字段。在PostgreSQL本身中创建它并不是问题,但我必须通过import org.apache.struts2.components.Text;类+ hibernate创建它。

我做了什么:

导入*.hbm.xml

生成的getter / setter。在我的<property name="base64signed" column="base64signed" /> 文件中添加了一行。

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ScreenCapture {

    public static void main(String[] args) throws IOException {
        System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.flipkart.com/");
        driver.manage().window().maximize();
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
        File capture = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(capture, new File("C:\\Users\\Vishvambruth JT\\Desktop\\FlipKart.jpg"));
    }
}

我收到了这个错误:

  

无法确定:org.apache.struts2.components.Text

的类型

2 个答案:

答案 0 :(得分:0)

我认为你应该使用这个注释:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\ARM\Microsoft.Cpp.ARM.Common.props

答案 1 :(得分:0)

我不认为Hibernate支持将org.apache.struts2.components.Text转换为DB&#39的varchar。

所以你把它存储为上面提到的LOB或CLOB

@Lob
private Text base64signed;

或者,您可以通过声明“base64signed”来轻松实现。如果字段为String,则在DB

中占用的内存较少
@Column
private String base64signed;