在保存常规时无法使数据库状态与会话错误同步 [英] could not synchronize database state with session error while saving in groovy

查看:105
本文介绍了在保存常规时无法使数据库状态与会话错误同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ c $ 

c>错误500:执行控制器[se.accumulate.wizard.SubmissionController]的操作[save]导致异常:
无法反序列化;嵌套异常是
org.hibernate.type.SerializationException:无法反序列化java.io.StreamCorruptedException $ b $ java.util.Hashtable.reconstitutionPut(Hashtable.java:889)$ b $ java.util .Hashtable.readObject(Hashtable.java:861)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject( ObjectInputStream.java:351)
at se.accumulate.wizard.PackagingService $$ EnhancerByCGLIB $$ 2b5048f.createPackage(< generated>)

解决此问题的任何想法/提示。我检查了数据库中域的任何不一致之处,等等,一切看起来都很好。

示例代码:

  def createPackage(提交提交){
logger.info(Creating submission package);
def xml = createZip(提交);

$ b def createZip(提交提交){
def sw = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(sw);
Customer customer = Customer.get(submission.customerId);
String custDir = customer.ftpCustomerTempDirectory
logger.info(Zip file:+ submission.fileName);

final int BUFFER = 2048;
尝试{
String tmpFileName = custDir +/+ java.util.UUID.randomUUID()。toString()。replaceAll( - ,)+.zip;

FileOutputStream fos = new FileOutputStream(tmpFileName);
BufferedOutputStream dest;
ZipOutputStream zos = new ZipOutputStream(fos);
FileInputStream fis = new FileInputStream(custDir +/+ submission.fileName);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry条目; ((entry = zis.getNextEntry())!= null){
//System.out.println(\"Extracting:+ entry);如果((entry.isDirectory()){
if((entry.getName()。toLowerCase()。endsWith(。jar)|| entry.getName())返回

。 toLowerCase()。endsWith(.jad)|| entry.getName()。toLowerCase()。endsWith(。apk))){
int count;
byte [] data = new byte [BUFFER];

String name = entry.getName();
if(name.indexOf('/')> = 0){
String [] parts = name.split('/');
name = parts [parts.length - 1];
}
zos.putNextEntry(new ZipEntry(Applications /+ name)); ((count = zis.read(data,0,BUFFER))!= -1){
zos.write(data,0,count);

}
zos.closeEntry();
}
}
}
zis.close();

if(submission.applicationImage!= null){
zos.putNextEntry(new ZipEntry(thumbnail_60x60.png));
zos.write(submission.applicationImage);
zos.closeEntry();
}

zos.putNextEntry(new ZipEntry(Submission.xml));
zos.write(createXml(submission).toString()。getBytes(UTF-8));
zos.close();


FtpClientService fcs = new FtpClientService();
fcs.putFile(customer.ftpUser,customer.ftpPassword,customer.ftpHost,customer.ftpPackagedDirectory,tmpFileName,submission.outputFileName);
logger.info(check 1)
if(!new File(tmpFileName).delete()){
logger.info(Could not delete tmp file+ tmpFileName);

logger.info(check 2)
if(!new File(custDir +/+ submission.fileName).delete()){
logger.info (无法删除提交文件+ submission.fileName);
}
logger.info(check 3)
} catch(Exception e){
e.printStackTrace();
}
logger.info(check 4)
returnsw;
}

已经显示所有日志检查1至4,并且预期的输出/文件已经创建了,但是这个异常已经被抛出......



我的域类:(Submission.groovy是哪个extneds向导)

  package se.accumulate.wizard 

class Submission extends Wizard {
long operatingSystemId
long deploymentId
int newOrExisting

字符串applicationName
字符串applicationShortName
字符串reportingName
字节[] applicationImage
long contentProviderId

字符串文件名
String outputFileName

属性deviceMapping

long applicationId

int overwriteExistingApplicationDetails

static constraints = {
operatingSystemId( nullable:true)
deploymentId(可空:true)
newOrExisting(可空:true)
applicationName(n
applicationShortName(可为空)
reportingName(可空:true)
applicationImage(可为空,true,maxSize:1048576)
contentProviderId(可为null)
$ fileName(nullable:true)
deviceMapping(nullable:true,maxSize:5242880)
outputFileName(可为空)
}
}

包se.accumulate.wizard

抽象类向导{
日期dateCreated
日期lastUpdated
long createdByUserId
long customerId
Boolean isConfirmed = false
int pageTracker
}

我的数据库表格提交描述如下:不适用格式化)

字段类型空键默认值



'application_id','bigint(20)' ,'NO','',NULL,''
'application_image','blob','YES','',NULL''
'applicat ion_name','varchar(255)','YES','',NULL,''
'cms_id','varchar(255)','YES','',NULL''
'content_provider_id','bigint(20)','NO','',NULL,''
'created_by_user_id','bigint(20)unsigned','NO','',NULL''
'date_created','datetime','NO','',NULL,''
'deployment_id','bigint(20)','NO','',NULL''
'device_mapping','blob','YES','',NULL,'
'file_name','varchar(255)','YES','',NULL''
'is_confirmed','tinyint(1)','NO','',NULL,''
'last_updated','datetime','NO','',NULL''
'new_or_existing','int(11)','NO','',NULL''
'operating_system_id','bigint(20)','NO','',NULL''
'overwrite_existing_application_details','int(11)','NO','',NULL''
'customer_id','bigint(20)','YES','MUL',NULL,''
'output_file_name','varchar(255)','YES','',NULL''
'reporting_name','varchar(255)','YES','',NULL,''
'application_short_name','varchar(255)','YES','',NULL'' '
'page_tracker','int(11)','YES','',NULL,''


另一种方法的一部分从createPackage(更改此方法后,错误显示) - 我刚过滤了?从文件名

  def createXml(提交提交){
Application application = Application.get(submission.getApplicationId() );
ContentProvider contentProvider = ContentProvider.get(submission.getContentProviderId());

Document doc = DocumentBuilderFactory.newInstance()。newDocumentBuilder()。newDocument();
元素rootElement = doc.createElement(game);
rootElement.setAttribute(title,submission.applicationName);
rootElement.setAttribute(short,submission.applicationShortName);
rootElement.setAttribute(externalRef,application.cmsId);
rootElement.setAttribute(contentPartner,contentProvider.name);

if(submission.applicationImage!= null){
Element image = doc.createElement(image);
image.setAttribute(type,thumbnail);
image.setAttribute(mime-type,image / png);
image.setAttribute(width,60);
image.setAttribute(height,60);
image.setTextContent(thumbnail_60x60.png);
rootElement.appendChild(image);
}

属性ps = submission.deviceMapping;
属性dm =(属性)ps; (def device:dm)
{
device.key = device.key.split(\\?)[0];
logger.debug(key = $ {device.key},value = $ {device.value})
if(!(device.value == null ||null.equalsIgnoreCase( device.value))){
logger.info(Adding handset:+ device.value);
Element handset = doc.createElement(handset);
handset.setAttribute(name,device.value);

String name = device.key;
if(name.indexOf('/')> = 0){
String [] parts = name.split('/');
name = parts [parts.length - 1];

$ b $ if元素jadFile = doc.createElement()。 jadfile将给);
jadFile.setTextContent(Applications /+ name);
handset.appendChild(jadFile);

/ *
name = getJarFileName();
if(name.indexOf('/')> = 0){
String [] parts = name.split('/');
name = parts [parts.length - 1];
} * /

元素jarFile = doc.createElement(jarfile);
jarFile.setTextContent(Applications /+ name.replace(.jad,.jar));
handset.appendChild(jarFile);
}
else {
// android
元素jarFile = doc.createElement(jarfile);
jarFile.setTextContent(Applications /+ name);
handset.appendChild(jarFile);
}

rootElement.appendChild(handset);
}
}
doc.appendChild(rootElement);

StringWriter xmlString = new StringWriter();
尝试{
Result result = new StreamResult(xmlString);
来源=新的DOMSource(doc);

//将DOM文档写入文件
Transformer xformer = TransformerFactory.newInstance()。newTransformer();
xformer.transform(source,result);

} catch(Exception e){
e.printStackTrace();
}
logger.info(XML:+ xmlString.toString());

return xmlString;


解决方案

b
$ b


在createXml方法中将属性更改为String,错误已被消除....




 属性ps = submission.deviceMapping; 
属性dm =(属性)ps; (def device:dm)
{
device.key = device.key.split(\\?)[0];

替换为

  java.util.Properties dm = submission.deviceMapping; 
for(String fileName:dm.keys()){
String device = dm.getProperty(fileName);
fileName = fileName.split(\\?)[0];


I am getting the below error and stack trace while trying to save/create a package in my save method of groovy controller.

Error 500: Executing action [save] of controller [se.accumulate.wizard.SubmissionController] caused exception:
  could not deserialize; nested exception is
    org.hibernate.type.SerializationException: could not deserialize java.io.StreamCorruptedException
      at java.util.Hashtable.reconstitutionPut(Hashtable.java:889)
      at java.util.Hashtable.readObject(Hashtable.java:861)
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
      at se.accumulate.wizard.PackagingService$$EnhancerByCGLIB$$2b5048f.createPackage(<generated>)

Any ideas/hints on resolving this issue. I have checked for any inconsistencies of the domain with the Database, etc. everything looks fine to me.

sample code :

def createPackage(Submission submission){
        logger.info("Creating submission package");
        def xml = createZip(submission);
    }

def createZip(Submission submission){
        def sw = new StringWriter()
        def xml = new groovy.xml.MarkupBuilder(sw);
        Customer customer = Customer.get(submission.customerId);
        String custDir = customer.ftpCustomerTempDirectory
        logger.info("Zip file: " + submission.fileName);

        final int BUFFER = 2048;
        try {
            String tmpFileName = custDir+"/" + java.util.UUID.randomUUID().toString().replaceAll("-", "") + ".zip";

            FileOutputStream fos = new FileOutputStream(tmpFileName);
            BufferedOutputStream dest;
            ZipOutputStream zos = new ZipOutputStream(fos);
            FileInputStream fis = new FileInputStream(custDir+"/" + submission.fileName);
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while((entry = zis.getNextEntry()) != null) {
                //System.out.println("Extracting: " +entry);

                if (!entry.isDirectory()) {
                    if((entry.getName().toLowerCase().endsWith(".jar") || entry.getName().toLowerCase().endsWith(".jad") || entry.getName().toLowerCase().endsWith(".apk"))){
                        int count;
                        byte[] data = new byte[BUFFER];

                        String name = entry.getName();
                        if (name.indexOf('/') >= 0) {
                            String[] parts = name.split('/');
                            name = parts[parts.length - 1];
                        }
                        zos.putNextEntry(new ZipEntry("Applications/" + name));
                        while ((count = zis.read(data, 0, BUFFER))!= -1) {
                            zos.write(data, 0, count);
                        }
                        zos.closeEntry();
                    }
                }
            }
            zis.close();

            if (submission.applicationImage != null) {
                zos.putNextEntry(new ZipEntry("thumbnail_60x60.png"));
                zos.write(submission.applicationImage);
                zos.closeEntry();
            }

            zos.putNextEntry(new ZipEntry("Submission.xml"));
            zos.write(createXml(submission).toString().getBytes("UTF-8"));
            zos.close();


            FtpClientService fcs = new FtpClientService();
            fcs.putFile(customer.ftpUser, customer.ftpPassword, customer.ftpHost, customer.ftpPackagedDirectory, tmpFileName, submission.outputFileName);
            logger.info("check 1")
            if (!new File(tmpFileName).delete()) {
                logger.info("Could not delete tmp file " + tmpFileName);
            }
            logger.info("check 2")
            if (!new File(custDir+"/" + submission.fileName).delete()) {
                logger.info("Could not delete submission file " + submission.fileName);
            }
            logger.info("check 3")
        } catch(Exception e) {
            e.printStackTrace();
        }
        logger.info("check 4")
        return "sw";
    }

All the logs check 1 to 4 have been displayed and the expected output/file has been created but this exception has been thrown...

My domain class :(Submission.groovy which extneds wizard)

package se.accumulate.wizard

class Submission extends Wizard {
    long operatingSystemId
    long deploymentId
    int newOrExisting

    String applicationName
    String applicationShortName
    String reportingName
    byte[] applicationImage
    long contentProviderId

    String fileName
    String outputFileName

    Properties deviceMapping

    long applicationId

    int overwriteExistingApplicationDetails

    static constraints = {
        operatingSystemId (nullable:true)
        deploymentId (nullable:true)
        newOrExisting (nullable:true)
        applicationName (nullable:true)
        applicationShortName (nullable:true)
        reportingName (nullable:true)
        applicationImage (nullable:true, maxSize: 1048576)
        contentProviderId (nullable:true)
        fileName (nullable:true)
        deviceMapping (nullable:true, maxSize: 5242880)
        outputFileName (nullable:true)
    }
}

package se.accumulate.wizard

abstract class Wizard {
    Date dateCreated
    Date lastUpdated
    long createdByUserId
    long customerId
    Boolean isConfirmed = false
    int pageTracker
}

My DB table submission description as below :(sorry for the improper formatting)

Field Type Null Key Default

'application_id', 'bigint(20)', 'NO', '', NULL, '' 'application_image', 'blob', 'YES', '', NULL, '' 'application_name', 'varchar(255)', 'YES', '', NULL, '' 'cms_id', 'varchar(255)', 'YES', '', NULL, '' 'content_provider_id', 'bigint(20)', 'NO', '', NULL, '' 'created_by_user_id', 'bigint(20) unsigned', 'NO', '', NULL, '' 'date_created', 'datetime', 'NO', '', NULL, '' 'deployment_id', 'bigint(20)', 'NO', '', NULL, '' 'device_mapping', 'blob', 'YES', '', NULL, '' 'file_name', 'varchar(255)', 'YES', '', NULL, '' 'is_confirmed', 'tinyint(1)', 'NO', '', NULL, '' 'last_updated', 'datetime', 'NO', '', NULL, '' 'new_or_existing', 'int(11)', 'NO', '', NULL, '' 'operating_system_id', 'bigint(20)', 'NO', '', NULL, '' 'overwrite_existing_application_details', 'int(11)', 'NO', '', NULL, '' 'customer_id', 'bigint(20)', 'YES', 'MUL', NULL, '' 'output_file_name', 'varchar(255)', 'YES', '', NULL, '' 'reporting_name', 'varchar(255)', 'YES', '', NULL, '' 'application_short_name', 'varchar(255)', 'YES', '', NULL, '' 'page_tracker', 'int(11)', 'YES', '', NULL, ''

part of another method which would be called from createPackage(after changing this method, the error is showing up)- i have just filtered the "?" from the filename

def createXml(Submission submission){
    Application application = Application.get(submission.getApplicationId());
    ContentProvider contentProvider = ContentProvider.get(submission.getContentProviderId());

    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element rootElement = doc.createElement("game");
    rootElement.setAttribute("title", submission.applicationName);
    rootElement.setAttribute("short", submission.applicationShortName);
    rootElement.setAttribute("externalRef", application.cmsId);
    rootElement.setAttribute("contentPartner", contentProvider.name);

    if (submission.applicationImage != null) {
        Element image = doc.createElement("image");
        image.setAttribute("type", "thumbnail");
        image.setAttribute("mime-type", "image/png");
        image.setAttribute("width", "60");
        image.setAttribute("height", "60");
        image.setTextContent("thumbnail_60x60.png");
        rootElement.appendChild(image);
    }

    Properties ps = submission.deviceMapping;
    Properties dm = (Properties) ps;
    for (def device : dm) {
        device.key = device.key.split("\\?")[0];
        logger.debug("key=${device.key}, value=${device.value}")
        if (!(device.value == null || "null".equalsIgnoreCase(device.value))) {
            logger.info("Adding handset: " + device.value);
            Element handset = doc.createElement("handset");
            handset.setAttribute("name", device.value);

            String name = device.key;
            if (name.indexOf('/') >= 0) {
                String[] parts = name.split('/');
                name = parts[parts.length - 1];
            }

            if (name.toLowerCase().endsWith(".jad")) {
                // java and blackberry
                Element jadFile = doc.createElement("jadfile");
                jadFile.setTextContent("Applications/" + name);
                handset.appendChild(jadFile);

                /*
                name = getJarFileName();
                if (name.indexOf('/') >= 0) {
                    String[] parts = name.split('/');
                    name = parts[parts.length - 1];
                }*/

                Element jarFile = doc.createElement("jarfile");
                jarFile.setTextContent("Applications/" + name.replace(".jad", ".jar"));
                handset.appendChild(jarFile);
            }
            else {
                // android
                Element jarFile = doc.createElement("jarfile");
                jarFile.setTextContent("Applications/" + name);
                handset.appendChild(jarFile);
            }

            rootElement.appendChild(handset);
        }
    }
    doc.appendChild(rootElement);

    StringWriter xmlString = new StringWriter();
    try{
        Result result = new StreamResult(xmlString);
        Source source = new DOMSource(doc);

        // Write the DOM document to the file
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.transform(source, result);

    } catch (Exception e){
        e.printStackTrace();
    }
    logger.info("XML: " + xmlString.toString());

    return  xmlString;
}

解决方案

By

changing the properties to String in the createXml method, the error has been eliminated....

Properties ps = submission.deviceMapping;
    Properties dm = (Properties) ps;
    for (def device : dm) {
        device.key = device.key.split("\\?")[0];

replaced with

java.util.Properties dm = submission.deviceMapping;
        for (String fileName : dm.keys()) {
            String device = dm.getProperty(fileName);
            fileName = fileName.split("\\?")[0];

这篇关于在保存常规时无法使数据库状态与会话错误同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆