Index: modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ProfileTest.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ProfileTest.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ProfileTest.java	(revision 47260)
@@ -47,7 +47,7 @@
     public void login(){
         User user = null;
         try {
-            user = um.login("ant.lebesis@gmail.com","1234");
+            user = um.login("p4@di.uoa.gr","1234");
         } catch (PersonManagerException e) {
             e.printStackTrace();
         }
Index: modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ManageRequestsTest.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ManageRequestsTest.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/ManageRequestsTest.java	(revision 47260)
@@ -12,6 +12,8 @@
 
 import javax.transaction.Transactional;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -44,6 +46,8 @@
     JournalManager jm;
     @Autowired
     PublisherManager pubm;
+    @Autowired
+    InvoiceManager im;
 
     @Test
     @Transactional
@@ -168,6 +172,8 @@
             c_list.add(c);
             r.setRequestComments(c_list);
 
+            r.setInvoice(new Invoice());
+
             rm.saveRequest(r);
         } catch (ManagerException e) {
             e.printStackTrace();
@@ -181,12 +187,12 @@
         User user = null;
 
         try {
-            user = um.getByEmail("pkanakakis@di.uoa.gr");
+            user = um.getByEmail("p4@di.uoa.gr");
         } catch (PersonManagerException e) {
             e.printStackTrace();
         }
 
-        RequestPage rs = rm.getRequests(null, null, RequestSort.USER, RequestSortOrder.DESCENDING, null, null, null, 0, 9);
+        RequestPage rs = rm.getForUser("p4@di.uoa.gr", null,null, RequestSort.DATE, null, null,null, null, 0, 9);
 
         List<Request> rss = rs.getRequests();
         for(Request r:rss) {
@@ -219,6 +225,30 @@
     }
 
 
+    @Test
+    @Transactional
+    @Rollback(true)
+    public void downaloadInvoiceFile() throws PersonManagerException, ManagerException {
+        InvoiceFile file = im.downloadInvoice("portal::7fff9073-4aa1-4713-9147-09365ef04a12");
+    }
 
+    @Test
+    @Transactional
+    @Rollback(true)
+    public void uploadInvoiceFile() throws PersonManagerException, ManagerException {
+        Request r = rm.getById("20170514-1508");
+        Invoice inv = new Invoice();
+        inv = im.saveInvoice(inv);
+        InputStream inputStream = new InputStream() {
+            @Override
+            public int read() throws IOException {
+                return 0;
+            }
+        };
+        inv = im.uploadInvoice(inv.getId(),"application/octet-stream",inputStream);
+        r.setInvoice(inv);
+    }
 
+
+
 }
\ No newline at end of file
Index: modules/uoa-goldoa-service/branches/hibernate/src/test/resources/hibernate-cfg.xml
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/test/resources/hibernate-cfg.xml	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/test/resources/hibernate-cfg.xml	(revision 47260)
@@ -7,7 +7,7 @@
 
 <hibernate-configuration>
     <session-factory>
-		<property name="hibernate.hbm2ddl.auto">update</property>
+		<property name="hibernate.hbm2ddl.auto">create</property>
         <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
         <property name="show_sql">true</property>
        	<property name="connection.pool_size">1</property>
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/RequestManagerImpl.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/RequestManagerImpl.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/RequestManagerImpl.java	(revision 47260)
@@ -594,7 +594,9 @@
 
 	@Override
 	public void invoiceUploaded(final String requestId, String invoiceId) {
+
 		final Request request = getById(requestId);
+
 		final List<User> moderators = userManager.getModerators();
 		executorService.submit(new Runnable() {
 			@Override
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManagerImpl.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManagerImpl.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManagerImpl.java	(revision 47260)
@@ -4,6 +4,8 @@
 import eu.dnetlib.goldoa.domain.InvoiceFile;
 import eu.dnetlib.goldoa.domain.ManagerException;
 import eu.dnetlib.goldoa.service.dao.InvoiceDAO;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -21,6 +23,7 @@
 	@Autowired
 	private InvoiceDAO invoiceDAO;
 
+	private Log logger = LogFactory.getLog(InvoiceManagerImpl.class);
 	@Override
 	public Invoice saveInvoice(Invoice invoice) {
 		if (invoice.getId() == null) {
@@ -40,10 +43,11 @@
 	}
 
 	@Override
-	public void uploadInvoice(final String invoiceId, final String mimetype, InputStream invoice) throws ManagerException {
+	public Invoice uploadInvoice(final String invoiceId, final String mimetype, InputStream invoice) throws ManagerException {
 		try {
-		    invoiceDAO.uploadInvoice(invoiceId,mimetype,invoice);
+		    return invoiceDAO.uploadInvoice(invoiceId,mimetype,invoice);
 		} catch (Exception e) {
+			logger.debug("uploadInvoice",e);
 			throw new ManagerException(ManagerException.ErrorCause.UNKNOWN);
 		}
 	}
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/InvoiceDAO.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/InvoiceDAO.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/InvoiceDAO.java	(revision 47260)
@@ -3,7 +3,10 @@
 import eu.dnetlib.goldoa.domain.Budget;
 import eu.dnetlib.goldoa.domain.File;
 import eu.dnetlib.goldoa.domain.Invoice;
+import eu.dnetlib.goldoa.service.RequestManagerImpl;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hibernate.criterion.Restrictions;
 import org.springframework.stereotype.Repository;
 
@@ -10,6 +13,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -18,9 +22,24 @@
 @Repository
 public class InvoiceDAO extends AbstractDao<String, Invoice>{
 
+    private Log logger = LogFactory.getLog(InvoiceDAO.class);
 
     public Invoice saveInvoice(Invoice invoice) {
-        persist(invoice);
+
+        Invoice i = getByKey(invoice.getId());
+        Invoice i_merged = null;
+
+        if(i!=null) {
+            logger.debug("Merge invoice with id " + i.getId());
+
+            if(i.getFile()!=null)
+                invoice.setFile(i.getFile());
+
+
+            i_merged = (Invoice) getSession().merge(invoice);
+        }else
+            persist(invoice);
+
         return invoice;
     }
 
@@ -33,19 +52,25 @@
         return null;
     }
 
-    public void uploadInvoice(String invoiceId, String mimetype, InputStream invoice) throws IOException {
+    public Invoice uploadInvoice(String invoiceId, String mimetype, InputStream inputStream) throws IOException {
         Invoice inv = getByKey(invoiceId);
 
         ByteArrayOutputStream baos = null;
         baos = new ByteArrayOutputStream();
-        IOUtils.copy(invoice, baos);
+        IOUtils.copy(inputStream, baos);
         IOUtils.closeQuietly(baos);
 
+
         File file = new File();
+        file.setId(getFileId());
         file.setMimetype(mimetype);
         file.setFile(baos.toByteArray());
 
         inv.setFile(file);
-        persist(inv);
+        return inv;
     }
+
+    private BigInteger getFileId(){
+        return (BigInteger) getSession().createSQLQuery("select nextval('file_id_seq') as id").list().get(0);
+    }
 }
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/RequestDAO.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/RequestDAO.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/RequestDAO.java	(revision 47260)
@@ -5,6 +5,7 @@
 import eu.dnetlib.goldoa.domain.*;
 import eu.dnetlib.goldoa.domain.RequestPage;
 import eu.dnetlib.goldoa.service.EligibilityManager;
+import eu.dnetlib.goldoa.service.InvoiceManager;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
@@ -37,6 +38,8 @@
 	private final static String GET_COMMENT_TEMPLATES = "select id, status, name, comment from commenttemplate where status=?";
 	@Autowired
 	private EligibilityManager eligibilityManager;
+	@Autowired
+	private InvoiceManager invoiceManager;
 
 	public void saveRequest(final Request request) {
 		Request r = getRequest(request.getId());
@@ -53,6 +56,9 @@
 				request.getBankAccount().setId(getBankId());
 		}
 
+		if(request.getInvoice()!=null)
+			invoiceManager.saveInvoice(request.getInvoice());
+
 		if(r != null){
 			logger.debug("Request submition with id -> " + r.getId());
 			logger.debug("Submition request co funders list size -> " + r.getRequestCoFunders().size());
@@ -80,9 +86,9 @@
 		}
 	}
 
+
 	public BigInteger getBankId() {
 		return (BigInteger) getSession().createSQLQuery("select nextval('bank_id_seq') as id").list().get(0);
-
 	}
 
 
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/PublicationDAO.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/PublicationDAO.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/PublicationDAO.java	(revision 47260)
@@ -12,6 +12,7 @@
 import org.springframework.stereotype.Repository;
 
 import javax.sql.DataSource;
+import java.math.BigInteger;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -52,4 +53,7 @@
 		return publication;
 	}
 
+	public BigInteger generateIdentifierID() {
+		return (BigInteger) getSession().createSQLQuery("select nextval('identifier_id_seq') as id").list().get(0);
+	}
 }
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/PublicationManagerImpl.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/PublicationManagerImpl.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/PublicationManagerImpl.java	(revision 47260)
@@ -57,6 +57,11 @@
 			publication.setId("portal::" + DigestUtils.md5Hex(publication.getTitle()));
 		}
 
+		if(publication.getIdentifiers() != null){
+			for(Identifier id : publication.getIdentifiers())
+				id.setId(this.generateId());
+		}
+
 		/*if (publication.getJournal() != null) {
 			if (!"doaj".equals(publication.getJournal().getSource())) {
 				if (publication.getJournal().getPublisher() != null && !"doaj".equals(publication.getJournal().getPublisher().getSource())){
@@ -200,4 +205,9 @@
 
 		return c.getTime();
 	}
+
+	private BigInteger generateId(){
+		return publicationDAO.generateIdentifierID();
+	}
+
 }
\ No newline at end of file
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManager.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManager.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/InvoiceManager.java	(revision 47260)
@@ -17,7 +17,7 @@
 
 	public Invoice getInvoice(String invoiceId) throws ManagerException;
 
-	void uploadInvoice(String invoiceId, String mimetype, InputStream invoice) throws ManagerException;
+	Invoice uploadInvoice(String invoiceId, String mimetype, InputStream invoice) throws ManagerException;
 
 	public InvoiceFile downloadInvoice(String invoiceId) throws ManagerException;
 }
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/File.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/File.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/File.java	(revision 47260)
@@ -1,6 +1,7 @@
 package eu.dnetlib.goldoa.domain;
 
 import java.io.Serializable;
+import java.math.BigInteger;
 import javax.persistence.*;
 
 
@@ -12,8 +13,7 @@
 public class File implements Serializable {
 	private static final long serialVersionUID = 1L;
 	@Id
-	@Column(columnDefinition = "text")
-	private String id;
+	private BigInteger id;
 	
 	private byte[] file;
 	
@@ -39,4 +39,11 @@
 		this.mimetype = mimetype;
 	}
 
+	public BigInteger getId() {
+		return id;
+	}
+
+	public void setId(BigInteger id) {
+		this.id = id;
+	}
 }
\ No newline at end of file
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Identifier.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Identifier.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Identifier.java	(revision 47260)
@@ -3,6 +3,7 @@
 import com.fasterxml.jackson.annotation.JsonBackReference;
 
 import java.io.Serializable;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import javax.persistence.*;
@@ -18,8 +19,7 @@
 	private static final long serialVersionUID = 1L;
 
 	@Id
-	@GeneratedValue(strategy = GenerationType.AUTO)
-	private Integer id;
+	private BigInteger id;
 	@Column(columnDefinition = "text")
 	private String value;
 	@Column(columnDefinition = "text")
@@ -53,4 +53,11 @@
 		this.type = type;
 	}
 
+	public BigInteger getId() {
+		return id;
+	}
+
+	public void setId(BigInteger id) {
+		this.id = id;
+	}
 }
\ No newline at end of file
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Request.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Request.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Request.java	(revision 47260)
@@ -102,7 +102,7 @@
 	@Convert( converter=CurrencyConverter.class )
 	private Currency currency = Currency.EUR;
 
-	@OneToOne(cascade = CascadeType.ALL)
+	@OneToOne
 	@JoinColumn(name = "invoice")
 	private Invoice invoice;
 
Index: modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Invoice.java
===================================================================
--- modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Invoice.java	(revision 47259)
+++ modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/Invoice.java	(revision 47260)
@@ -19,9 +19,9 @@
 	private String alternativeid;
 	@Temporal(TemporalType.DATE)
 	private Date date;
-	
-	
-	@OneToOne
+
+
+	@OneToOne(cascade = CascadeType.ALL)
 	@JoinColumn(name = "file")
 	private File file;
 
